mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd4057ea61 | ||
|
|
d6a6c4196f | ||
|
|
04dc129c61 | ||
|
|
98925a39b9 | ||
|
|
77503df677 | ||
|
|
0146e1a1cc | ||
|
|
de4580d07c | ||
|
|
54db971610 | ||
|
|
eef2190e08 | ||
|
|
470f4a115a | ||
|
|
6c4e97deac | ||
|
|
89580103fb | ||
|
|
ae605157db | ||
|
|
a9e0cd5c5e | ||
|
|
cf0881b843 | ||
|
|
6b82e15c14 | ||
|
|
d2aee8af0f | ||
|
|
3da972ddc9 | ||
|
|
baa36cf571 | ||
|
|
ccea8ae8d1 | ||
|
|
6664219057 | ||
|
|
1453bd2778 | ||
|
|
cf7c102b93 | ||
|
|
a6e1b8c338 | ||
|
|
6e74146466 | ||
|
|
a972bd26f7 | ||
|
|
b09dfa22ec | ||
|
|
f21d2bd4ea | ||
|
|
f3dec30c27 | ||
|
|
bcb453e7ea | ||
|
|
1b2d3d0e6e | ||
|
|
744c0d39b5 | ||
|
|
b75dd075bc | ||
|
|
1b48983bf6 | ||
|
|
9fbb705595 | ||
|
|
063a9a6859 | ||
|
|
434ceab25a | ||
|
|
a848eb9e76 | ||
|
|
eb2253a23a | ||
|
|
50b57b2cc1 | ||
|
|
d82d9ac7b9 | ||
|
|
82a48899f0 | ||
|
|
101bb826f1 | ||
|
|
662166d7c6 | ||
|
|
7e9bf45f3d | ||
|
|
49a97bd487 | ||
|
|
2f30395d00 | ||
|
|
8de2c9dafc | ||
|
|
66f2c79605 | ||
|
|
1a7ccce774 | ||
|
|
134339ae9d | ||
|
|
7df166a99e | ||
|
|
acc6e77ec5 | ||
|
|
38c4f1e4cc | ||
|
|
a6483fa895 | ||
|
|
40617692b8 | ||
|
|
a5ba986666 | ||
|
|
497ab52ff0 | ||
|
|
24baf77dba | ||
|
|
ce245f8885 | ||
|
|
e508031c98 | ||
|
|
4ed13cdd04 | ||
|
|
f31f13f77b | ||
|
|
e63f928a3c | ||
|
|
7b1ea17fb8 | ||
|
|
240ec95a74 | ||
|
|
ee45291533 | ||
|
|
f813aed1ce | ||
|
|
a62954d1a7 | ||
|
|
30582cfb05 | ||
|
|
355738d42b | ||
|
|
749e296796 | ||
|
|
e4d9cb95b4 | ||
|
|
98c7e224fe | ||
|
|
ac0faf78fd | ||
|
|
f08554758b | ||
|
|
b302014ee1 | ||
|
|
210199db1c | ||
|
|
d48eefceb0 | ||
|
|
394fdd00f0 | ||
|
|
78f62c8db8 | ||
|
|
a64b000459 | ||
|
|
1da7cb1c2f | ||
|
|
49b8c4c39f | ||
|
|
bf4ee72c0f | ||
|
|
3124b10eaa | ||
|
|
47969d9d50 | ||
|
|
c0a06a88c7 | ||
|
|
ab5f7071ce | ||
|
|
f42b239713 | ||
|
|
bfc51b8967 | ||
|
|
9c66a56a65 | ||
|
|
cea889bde5 | ||
|
|
78696aa822 | ||
|
|
1f8a76e534 | ||
|
|
d22f926a8a | ||
|
|
1c95619aa4 | ||
|
|
81ebc40158 | ||
|
|
1bf4073fa7 | ||
|
|
ab59a34604 | ||
|
|
31323e7bf1 | ||
|
|
05658ad5c5 | ||
|
|
a593a4a73e | ||
|
|
99972307dc | ||
|
|
d7fb49166f | ||
|
|
0bca7bc743 | ||
|
|
10a3fa5984 | ||
|
|
d98929f24c | ||
|
|
2ab6a94795 | ||
|
|
818f982c75 | ||
|
|
e72b571069 | ||
|
|
2a92ce78f5 | ||
|
|
b512702fbb | ||
|
|
47fca9f4ff | ||
|
|
ee8c912397 | ||
|
|
3fd422008e | ||
|
|
bce4c98475 | ||
|
|
b45b0a8df4 | ||
|
|
b8af8d387c | ||
|
|
84075c5988 | ||
|
|
35919802f3 | ||
|
|
6b3a399015 | ||
|
|
80b763ecc3 | ||
|
|
85d5b10f61 | ||
|
|
5057792d4d | ||
|
|
a1d945a61f | ||
|
|
46425faaa9 | ||
|
|
4479387580 | ||
|
|
f355fb0dfe | ||
|
|
b759f25d87 | ||
|
|
f1e56cd353 | ||
|
|
04899d6528 | ||
|
|
bd7c424989 | ||
|
|
aa17bf06de | ||
|
|
6d2872a07f | ||
|
|
c12561074c | ||
|
|
bf92b04d6c | ||
|
|
7e93d2d169 | ||
|
|
2bb35dc613 | ||
|
|
26aa452c57 | ||
|
|
7a55a81186 | ||
|
|
c9359592d7 | ||
|
|
bf55aa50ce | ||
|
|
564c43c907 | ||
|
|
31bc6f79e5 | ||
|
|
e4c84c5f80 | ||
|
|
2d90aff408 | ||
|
|
820da037da | ||
|
|
00f38133e9 | ||
|
|
e231dc4dec | ||
|
|
549cb2284c | ||
|
|
d41287c320 | ||
|
|
b38b1731a0 | ||
|
|
1d807d10e9 | ||
|
|
08fa2f887d | ||
|
|
04280ecda4 | ||
|
|
f4b5ac2d16 | ||
|
|
c8e2a4d921 | ||
|
|
f6dc704aff | ||
|
|
b3f2a6cf20 | ||
|
|
ad44ce8ce4 | ||
|
|
4b13af6691 | ||
|
|
a941836a4d | ||
|
|
5a0a7b12e4 | ||
|
|
0835e6f9f4 | ||
|
|
d279ada718 | ||
|
|
e1849a2bfd | ||
|
|
362cfcbc83 | ||
|
|
6c093e141b | ||
|
|
aeac232e12 | ||
|
|
0ce96ffc12 | ||
|
|
ef6f2a40c8 | ||
|
|
3fbf0ddaa4 | ||
|
|
6572bf8ce3 | ||
|
|
f27b8ba1be | ||
|
|
f53a7cce32 | ||
|
|
e7eb1c8a66 | ||
|
|
e707d1f27a | ||
|
|
9a2303c495 | ||
|
|
6154b7cbe2 | ||
|
|
ffc7de4715 | ||
|
|
97339e4ce4 | ||
|
|
fc89fec3e6 | ||
|
|
15986a4e4f | ||
|
|
d56520d22a | ||
|
|
42f1871c84 | ||
|
|
f65f9b9845 | ||
|
|
f415a63b76 | ||
|
|
50e661f804 | ||
|
|
7ffafdc007 | ||
|
|
96875a1278 | ||
|
|
6766ca8647 | ||
|
|
fc13f6870b | ||
|
|
27d389c36a | ||
|
|
625e474c03 | ||
|
|
116a65ce77 | ||
|
|
c6116fcc88 | ||
|
|
86ce9b0bb1 | ||
|
|
6ca5b738d5 | ||
|
|
f660efcd54 | ||
|
|
5f826d6a9d | ||
|
|
873f8632e4 | ||
|
|
af7c22e7b3 | ||
|
|
28ec650e4f | ||
|
|
329bcc68b1 | ||
|
|
b3eb1f6419 | ||
|
|
2132922c7b | ||
|
|
9915c15086 | ||
|
|
6df1c7dd9d | ||
|
|
ec9987aab6 | ||
|
|
34e0ba84f1 | ||
|
|
d23f21b391 | ||
|
|
6696248158 | ||
|
|
02c8c8cde0 | ||
|
|
64a5a17df0 | ||
|
|
a649a688e7 | ||
|
|
8c42685e26 | ||
|
|
01ceaef8d7 | ||
|
|
55d7c8f09d | ||
|
|
1f59eceacf | ||
|
|
e14ede2510 | ||
|
|
bc05593dd2 | ||
|
|
4a71dbe7bb | ||
|
|
aed250a64d | ||
|
|
e2ad753f4a | ||
|
|
2ab23546ea | ||
|
|
9d9e826bb3 | ||
|
|
3c2887f8c3 | ||
|
|
8cc67b09c2 | ||
|
|
bb3e89e3af | ||
|
|
172dab7431 | ||
|
|
78da2457e8 | ||
|
|
7e70432495 | ||
|
|
c6060ad812 | ||
|
|
f09710a5f7 | ||
|
|
de727db4c6 | ||
|
|
671cd0c5da | ||
|
|
ef62e8b965 | ||
|
|
8c44da655c | ||
|
|
b5850f1cd2 | ||
|
|
0a61970b29 | ||
|
|
91a8e83f21 | ||
|
|
825314c869 | ||
|
|
8d9bc66a82 | ||
|
|
52f4d847dd | ||
|
|
ebf4b0e969 | ||
|
|
47237ff87b | ||
|
|
8d95aa5ed3 | ||
|
|
7ee8b9b2f0 | ||
|
|
1f2256ec81 | ||
|
|
0518f2ae2f | ||
|
|
3bf088f2c8 | ||
|
|
bd16b7c69e | ||
|
|
f5c91968a2 | ||
|
|
4e78ac33c5 | ||
|
|
e1acf5d160 | ||
|
|
047515d813 | ||
|
|
bdbeb742d4 | ||
|
|
e7d8e71297 | ||
|
|
a34e0a4737 | ||
|
|
2c026259b1 | ||
|
|
cd36df5500 | ||
|
|
5ea7b8c5f8 | ||
|
|
372b9cae7a | ||
|
|
595478ed6f | ||
|
|
a2776ddae1 | ||
|
|
f9338b8dd9 | ||
|
|
dee7090071 | ||
|
|
2a8e5538b2 | ||
|
|
20b2fb1bef | ||
|
|
f096eef66d | ||
|
|
899000b647 | ||
|
|
76824fb602 | ||
|
|
02af6da599 | ||
|
|
83afae5625 | ||
|
|
e5510dd9ae | ||
|
|
4d7c520f18 | ||
|
|
6f62f9dd98 | ||
|
|
31d7b056af | ||
|
|
9b49603c72 | ||
|
|
f192d11758 | ||
|
|
ae08c083ea | ||
|
|
dab9334c3a | ||
|
|
7fdfd6109f | ||
|
|
7d6e87a0d3 | ||
|
|
a20ebade09 | ||
|
|
8d6f77ea71 | ||
|
|
19ecc4f945 | ||
|
|
ebc618adea | ||
|
|
38669fd83b | ||
|
|
211f8adc0e | ||
|
|
bda85a66df | ||
|
|
babd8d974f | ||
|
|
9fc5bbb951 | ||
|
|
3fe6e3c09e | ||
|
|
289a14dc7a | ||
|
|
ba9fcd100d | ||
|
|
889dc32a0a | ||
|
|
f13f4e0023 | ||
|
|
4a425c4ecf | ||
|
|
293e869acb | ||
|
|
f3d7cd9dd7 | ||
|
|
fd5498e16b | ||
|
|
55f91c5d3f | ||
|
|
0831182e39 | ||
|
|
26153ca8ea | ||
|
|
7855770ca7 | ||
|
|
a81156c3e3 | ||
|
|
f31c71e430 | ||
|
|
7ba7bff3d5 | ||
|
|
11bb10b44b | ||
|
|
378965cc3d | ||
|
|
40b537767d | ||
|
|
e2e78c0682 | ||
|
|
0267fc82c9 | ||
|
|
c4022f466f | ||
|
|
17cdcc5560 | ||
|
|
5eaff7a8ce | ||
|
|
9d44ac0901 | ||
|
|
606c9dd9a8 | ||
|
|
ec7907ed71 | ||
|
|
d1e20a72e3 | ||
|
|
742662e4fc | ||
|
|
d3096ebaac | ||
|
|
c0e28b81a8 | ||
|
|
ce5edcb0c8 | ||
|
|
a3743f0293 | ||
|
|
92580f3515 | ||
|
|
50018010c7 | ||
|
|
e4294d78bf | ||
|
|
b73f5a157d | ||
|
|
ce9a1a6d9e | ||
|
|
a95b06f703 | ||
|
|
226c097b81 | ||
|
|
a18658fc16 | ||
|
|
971f6d79be | ||
|
|
ed67ab81a3 | ||
|
|
07304781ea | ||
|
|
941a405cf8 | ||
|
|
b60d3061b7 | ||
|
|
82e22174d6 | ||
|
|
cf9811d03a | ||
|
|
19f06fb3a2 | ||
|
|
5710758dd7 | ||
|
|
181e1d2e46 | ||
|
|
59fba285b5 | ||
|
|
fdf8543c7e | ||
|
|
86d8ae0911 | ||
|
|
900e58f0ad | ||
|
|
62e80c0c2f | ||
|
|
3483bebdb4 | ||
|
|
11d61359c1 | ||
|
|
30afcb6ddc | ||
|
|
ad45ce8499 | ||
|
|
9a489d13f4 | ||
|
|
721c70166c | ||
|
|
861c2d4f04 | ||
|
|
da203b69c5 | ||
|
|
159fe8d48e | ||
|
|
6adba32238 | ||
|
|
d96da6434f | ||
|
|
5f37421ceb | ||
|
|
6f64e729c8 | ||
|
|
288e088f8a | ||
|
|
3797fdbf1b | ||
|
|
3036f4676d | ||
|
|
e14b6677b2 | ||
|
|
76f966845d | ||
|
|
288d97f24c | ||
|
|
755dd7f60a | ||
|
|
e6d669d187 | ||
|
|
0d1a2d3010 | ||
|
|
51af94f12d | ||
|
|
8d7ca7fb03 | ||
|
|
bc691a9d86 | ||
|
|
2c79171be6 | ||
|
|
e91432f939 | ||
|
|
ea7b9db078 | ||
|
|
a22bc34816 | ||
|
|
2b76d8a53a | ||
|
|
5f6b924004 | ||
|
|
dfd4d82693 | ||
|
|
e5282f9852 | ||
|
|
b2c342e453 | ||
|
|
3aad040f28 | ||
|
|
e722ef3e8a | ||
|
|
e94be9acee | ||
|
|
ae5a1331b6 | ||
|
|
a0052b7b9a | ||
|
|
503ee92528 | ||
|
|
6c3715cc32 | ||
|
|
a5416f521a | ||
|
|
a8023bb41b | ||
|
|
fa01699786 | ||
|
|
5f1150cf4e | ||
|
|
5022ac89b4 | ||
|
|
382246905b | ||
|
|
a5241d27c1 | ||
|
|
4479ecb1bb | ||
|
|
b454ab45fe | ||
|
|
d06d80619e | ||
|
|
9a70c3bdb0 | ||
|
|
103ef6169c | ||
|
|
1a165ff64c | ||
|
|
8cbbb2ed50 | ||
|
|
781d9b46da | ||
|
|
ffa221192d | ||
|
|
751f964139 | ||
|
|
14f75d834a | ||
|
|
96efc99a00 | ||
|
|
45d2c8854d | ||
|
|
c22843f238 | ||
|
|
1c5009fcb0 | ||
|
|
bd63d1dcda | ||
|
|
8aaf211c5b | ||
|
|
8cc5838efe | ||
|
|
4b965c623b | ||
|
|
be27ceed00 | ||
|
|
1d75730d44 | ||
|
|
95d74a6940 | ||
|
|
c6ea3a374e | ||
|
|
e8ce805f2a | ||
|
|
3d898ebdf3 | ||
|
|
f45b7c47c8 | ||
|
|
916cb47b9d | ||
|
|
bce816139b | ||
|
|
24bce16c4d | ||
|
|
a928c67913 | ||
|
|
2b8f510603 | ||
|
|
e8273ecc61 | ||
|
|
e1f31a2da3 | ||
|
|
d897acfd3c | ||
|
|
1e57ac408a | ||
|
|
ef8522e101 | ||
|
|
c71d856a08 | ||
|
|
df7ff76404 | ||
|
|
0d1ce68d19 | ||
|
|
88aa249ce1 | ||
|
|
ff626ae0b5 | ||
|
|
529f23d836 | ||
|
|
cb88bab67d | ||
|
|
67a5c39b1c | ||
|
|
0273867c49 | ||
|
|
1e50d88183 | ||
|
|
29a832c68d | ||
|
|
cb05bd05eb | ||
|
|
4f45d7de35 | ||
|
|
a6ba9a0554 | ||
|
|
9c95bc17fe | ||
|
|
2c94cfee03 | ||
|
|
3c16870f86 | ||
|
|
22f45902ca | ||
|
|
28b1eb8524 | ||
|
|
1c8702d67a | ||
|
|
cf4913deb0 | ||
|
|
bdd441b1b6 | ||
|
|
4c9fe06229 | ||
|
|
e7da98b6bd | ||
|
|
dcdfaabedf | ||
|
|
524daa45a5 | ||
|
|
073b8fd981 | ||
|
|
d7749e0a2c | ||
|
|
7972a0f2a8 | ||
|
|
19dcb43658 | ||
|
|
9ed1a118e6 | ||
|
|
a5a5410515 | ||
|
|
40a4ca31b9 | ||
|
|
7f44ab2262 | ||
|
|
123c927b1a | ||
|
|
74274f164d | ||
|
|
5c2bd0b3bb | ||
|
|
d0a5a1e7be | ||
|
|
077e6ebae5 | ||
|
|
abe0c14301 | ||
|
|
61576d4032 | ||
|
|
782a8d2c3c | ||
|
|
e619dd2493 | ||
|
|
8a1055ed1b | ||
|
|
ff766b10eb | ||
|
|
ceb2276098 | ||
|
|
82f4d05f4b | ||
|
|
8a81cb4f9c | ||
|
|
1504bd2227 | ||
|
|
475f894582 | ||
|
|
7007e002e6 | ||
|
|
9af1b1a720 | ||
|
|
ca9657baf1 | ||
|
|
3e347746f9 | ||
|
|
b5987afaa6 | ||
|
|
ea46d08835 | ||
|
|
789114cc7d | ||
|
|
cf292fafcb | ||
|
|
08fca7de69 | ||
|
|
b42437c458 | ||
|
|
98e1787f93 | ||
|
|
7a0ec0ecd3 | ||
|
|
55b9f8bbe5 | ||
|
|
2968645f2e | ||
|
|
92dea0e404 | ||
|
|
bfd3077bd0 | ||
|
|
2d1616894d | ||
|
|
7c203b40c8 | ||
|
|
2f63a2fa17 | ||
|
|
e3e065a6d7 | ||
|
|
afd8ba8cf2 | ||
|
|
43d87b4791 | ||
|
|
6267685920 | ||
|
|
48882f3fec | ||
|
|
0ac54ea1ea | ||
|
|
4395ce01d7 | ||
|
|
2c097da12d | ||
|
|
5f316dc7a4 | ||
|
|
02a475e113 | ||
|
|
338bbe27a8 | ||
|
|
44564065f6 | ||
|
|
c54ec7be2d | ||
|
|
274e380b34 | ||
|
|
e872f08273 | ||
|
|
a6fda3b787 | ||
|
|
a48851888f | ||
|
|
f1abb66f9a | ||
|
|
c999c51d77 | ||
|
|
6bb5227ee1 | ||
|
|
cefe8698da | ||
|
|
4be6bad526 | ||
|
|
d3c913e384 | ||
|
|
a868f4eee4 | ||
|
|
44da89979f | ||
|
|
a79f07e4dc | ||
|
|
e17a96f5ec | ||
|
|
5062508940 | ||
|
|
9cf91328c1 | ||
|
|
6a30ef7017 | ||
|
|
71dabf5334 | ||
|
|
155b8cdad9 | ||
|
|
96dc02b249 | ||
|
|
eaddcab0ba | ||
|
|
d9b02ecd8d | ||
|
|
b9c12e44a4 | ||
|
|
58ed5bb56e | ||
|
|
094f44e92c | ||
|
|
566706dd62 | ||
|
|
60a76e9348 | ||
|
|
1d9b0f7fa5 | ||
|
|
f55ad323b4 | ||
|
|
78558e4c52 | ||
|
|
c9d4cc3321 | ||
|
|
0f8a464157 | ||
|
|
e4a675babb | ||
|
|
5b4ed01bec | ||
|
|
64df253053 | ||
|
|
d8129bd643 | ||
|
|
60a4738694 | ||
|
|
9ade14e076 | ||
|
|
6aa54b8dda | ||
|
|
0ff911cc26 | ||
|
|
b5b14b2f9d | ||
|
|
2b6f41e0d0 | ||
|
|
9b429cc751 | ||
|
|
ec56dffd19 | ||
|
|
a09f2093b5 | ||
|
|
b15d3be88a | ||
|
|
a26628ed50 | ||
|
|
0b5a798343 | ||
|
|
224ae50e91 | ||
|
|
03d7728d46 | ||
|
|
19ba15f2f1 | ||
|
|
9da9967b83 | ||
|
|
1510c45ecb | ||
|
|
9b76c9fe3e | ||
|
|
ea4564c827 | ||
|
|
0a97e4e038 | ||
|
|
8e19164977 | ||
|
|
ab60bb8d0b | ||
|
|
c7ca4d9b97 | ||
|
|
3c3d0b46db | ||
|
|
f08d9ba81e | ||
|
|
15a9ffd340 | ||
|
|
b9aae48517 | ||
|
|
e2864ab08c | ||
|
|
effe0198ce | ||
|
|
c5ac862cef | ||
|
|
cd77e361ab | ||
|
|
bc5fd44172 | ||
|
|
c781820bf6 | ||
|
|
30802affd4 | ||
|
|
eab021a5cb | ||
|
|
505b5e6468 | ||
|
|
5631485465 | ||
|
|
fafbd9a04f | ||
|
|
bc582e64cc | ||
|
|
df0044a110 | ||
|
|
503556196a | ||
|
|
fd961f9ff9 | ||
|
|
e3411670cb | ||
|
|
d134107aba | ||
|
|
5de1c23aba | ||
|
|
72b257e5d1 | ||
|
|
9d0bae2d03 | ||
|
|
ad6d5e9ec9 | ||
|
|
6462ceef24 | ||
|
|
c281b27220 | ||
|
|
1d5502dc3c | ||
|
|
4ef3c792de | ||
|
|
a5aac5754c | ||
|
|
23903a969d | ||
|
|
78020c4794 | ||
|
|
682f1900ae | ||
|
|
a9cb0cfb2a | ||
|
|
fc6a4872d6 | ||
|
|
284f58dec4 | ||
|
|
e51bc0cea5 | ||
|
|
da9770c99b | ||
|
|
266d45e13a | ||
|
|
703662cb5b | ||
|
|
833f74dce6 | ||
|
|
014aa90462 | ||
|
|
f5dcaebbf8 | ||
|
|
02a9e8d886 | ||
|
|
4fe8cf76bb | ||
|
|
d4ee43179c | ||
|
|
5afe1f1a25 | ||
|
|
7eb9a66837 | ||
|
|
aa33a1644c | ||
|
|
c42e1f28d6 | ||
|
|
fe21108f08 | ||
|
|
81f3b95914 | ||
|
|
2daad2d223 | ||
|
|
09becbfb04 | ||
|
|
1f9f2d2cf1 | ||
|
|
939d6d42bb | ||
|
|
45a9d45e3f | ||
|
|
cfca42e577 | ||
|
|
4c9b125cc8 | ||
|
|
e1e00c951b | ||
|
|
bc5153dd4a | ||
|
|
aed74479fd | ||
|
|
c14974d167 | ||
|
|
f07de5401d | ||
|
|
faf066f2b9 | ||
|
|
06640844e9 | ||
|
|
bfc703a556 | ||
|
|
ec01993d84 | ||
|
|
5a54b6a761 | ||
|
|
a605c435b6 | ||
|
|
05da1708eb | ||
|
|
3f826b8971 | ||
|
|
de8388f9a7 | ||
|
|
569f782a60 | ||
|
|
96b9b6a375 | ||
|
|
410502fa7e | ||
|
|
a8cd73cc69 | ||
|
|
54ce23d0a8 | ||
|
|
2d68b72dbd | ||
|
|
091cf4337c | ||
|
|
ff9b8a59e2 | ||
|
|
6e4544450e | ||
|
|
d4922beefe | ||
|
|
6f37ff9ea3 | ||
|
|
1dfa671405 | ||
|
|
eb1d5d0a6d | ||
|
|
a190d5cbd9 | ||
|
|
ab647ec0eb | ||
|
|
1fb9e37ec5 | ||
|
|
bcd057d45b | ||
|
|
0a63e2946d | ||
|
|
b63e42ecf2 | ||
|
|
ee2ec7fe54 | ||
|
|
1f63342c96 | ||
|
|
6e094a8edb | ||
|
|
2ece059c5e | ||
|
|
7866675a55 | ||
|
|
619579bee3 | ||
|
|
b5dbaff748 | ||
|
|
a0ce1efabe | ||
|
|
3fd45abad8 | ||
|
|
c1b557fbb9 | ||
|
|
babefd09f3 | ||
|
|
578e5dc063 | ||
|
|
2a290ff9c1 | ||
|
|
bfd60155b6 | ||
|
|
df09a1e3bf | ||
|
|
3cced5e29b | ||
|
|
bd5ecf8cbb | ||
|
|
3e6f7ef541 | ||
|
|
ac5b434641 | ||
|
|
00f917f52e | ||
|
|
a11770961e | ||
|
|
b0d33a5385 | ||
|
|
2d8f2422b3 | ||
|
|
0166059d1b | ||
|
|
50fcb45b88 | ||
|
|
29d13aef09 | ||
|
|
31036b8dee | ||
|
|
6f231f3367 | ||
|
|
97f08f21b7 | ||
|
|
9a26016ed4 | ||
|
|
f541613c6b | ||
|
|
6931b2944b | ||
|
|
3b3634bf5f | ||
|
|
0af9d0c972 | ||
|
|
daeecbe99e | ||
|
|
5d9194d03d | ||
|
|
3c7ce3de8b | ||
|
|
e56d4e63f4 | ||
|
|
57e6e90002 | ||
|
|
c7d2eb87ac | ||
|
|
7226fe5303 | ||
|
|
10af336cd1 | ||
|
|
f218a38294 | ||
|
|
2f326a8199 | ||
|
|
eb07a3c2f1 | ||
|
|
04526012f9 | ||
|
|
b5bb214920 | ||
|
|
1e587b0848 | ||
|
|
97727e0d1e | ||
|
|
723eab59d6 | ||
|
|
1421ccc81e | ||
|
|
e1d43b8eb2 | ||
|
|
67bd47f11f | ||
|
|
e44676e491 | ||
|
|
7b4d513e22 | ||
|
|
5b51cd06c0 | ||
|
|
052a47734f | ||
|
|
54767bf97d | ||
|
|
e5bace03f7 | ||
|
|
691fcfb657 | ||
|
|
49f7da4402 | ||
|
|
6c0ca42fff | ||
|
|
30c6cbefbd | ||
|
|
5a049642ea | ||
|
|
b168459007 | ||
|
|
d5c7b5f537 | ||
|
|
506ed000a0 | ||
|
|
b92e9216f4 | ||
|
|
6ff5079df8 | ||
|
|
d686fc04f4 | ||
|
|
9aef78be4f | ||
|
|
f6b1c080ad | ||
|
|
d4fa85688d | ||
|
|
20b4a33c00 | ||
|
|
f61055ebc0 | ||
|
|
777a02cbe9 | ||
|
|
61b1940397 | ||
|
|
eef6d267c3 | ||
|
|
9c48c296c8 | ||
|
|
214c61669a | ||
|
|
fb0396923f | ||
|
|
6503a300cc | ||
|
|
be80595834 | ||
|
|
54bda0ea95 | ||
|
|
6d23e18c11 | ||
|
|
5f8e7fcb73 | ||
|
|
214b52a96a | ||
|
|
d426d0faeb | ||
|
|
ebb51addd7 | ||
|
|
c64fab6ecb | ||
|
|
696bd6f316 | ||
|
|
7a3a661e2a | ||
|
|
f0949d296d | ||
|
|
d2ebcb24b9 | ||
|
|
644087b592 | ||
|
|
be2f5273d1 | ||
|
|
10053a8a1b | ||
|
|
9cefaec49c | ||
|
|
55b79c1518 | ||
|
|
c2ab86d4ba | ||
|
|
0e5fcde1e9 | ||
|
|
002cce886c | ||
|
|
151ea2ece4 | ||
|
|
568882a2ea | ||
|
|
f38d6d73f4 | ||
|
|
569893861d | ||
|
|
e81ac6f61e | ||
|
|
177098c957 | ||
|
|
1e78512c95 | ||
|
|
1b147151f0 | ||
|
|
ad8a26616f | ||
|
|
8f28823217 | ||
|
|
b509df78df | ||
|
|
5876cc7e17 | ||
|
|
de73a36399 | ||
|
|
c9aed600b6 | ||
|
|
318e035344 | ||
|
|
cd097232cb | ||
|
|
b7b783b6be | ||
|
|
968f503d80 | ||
|
|
7fc92e236b | ||
|
|
3062a29b78 | ||
|
|
3bea3ec3d8 | ||
|
|
0f66d454c1 | ||
|
|
6738d7472e | ||
|
|
500f38a496 | ||
|
|
3a5a70b56d | ||
|
|
15e132c824 | ||
|
|
2b3cf58b8a | ||
|
|
2998796c2c | ||
|
|
3978d0754d | ||
|
|
655b9a17e1 | ||
|
|
84a694d4c2 | ||
|
|
ebac8b92ba | ||
|
|
6a4326af39 | ||
|
|
6a51e8a1c9 | ||
|
|
006a90f681 | ||
|
|
17983e7fad | ||
|
|
a15b1805fb | ||
|
|
11e0bd79b0 | ||
|
|
bfbf4cb453 | ||
|
|
229509a067 | ||
|
|
ff5c43e6cb | ||
|
|
7cd3aae753 | ||
|
|
fe05b1de12 | ||
|
|
1903c8b557 | ||
|
|
456a96042f | ||
|
|
888df0ac53 | ||
|
|
18afe91a82 | ||
|
|
b8d0ed39d9 | ||
|
|
0c3f399de3 | ||
|
|
45ccabb11d | ||
|
|
d71a213c4b | ||
|
|
8e9123bdce | ||
|
|
2e3e65f3e7 | ||
|
|
9db53a4e3f | ||
|
|
c2e098e535 | ||
|
|
a6de2c2b44 | ||
|
|
9dad9ea38b | ||
|
|
1d938c93b6 | ||
|
|
35bc1bcb44 | ||
|
|
1438ebc12a | ||
|
|
61b29f6fab | ||
|
|
fb9b6886fa | ||
|
|
0e3eaf724b | ||
|
|
2a05ccbee1 | ||
|
|
59bee01c0a | ||
|
|
4e4c8d71be | ||
|
|
c7ae31dfce | ||
|
|
2ea80b0aab | ||
|
|
5bbf5ee3af | ||
|
|
748e9c5d86 | ||
|
|
8764beba39 | ||
|
|
1fc551fae0 | ||
|
|
8baf722343 | ||
|
|
cf4ce01ddd | ||
|
|
57d919e424 | ||
|
|
b0dc893a05 | ||
|
|
f5bb484226 | ||
|
|
29f3ffd474 | ||
|
|
b160e38f8f | ||
|
|
bc2714ab2a | ||
|
|
38d94e509f | ||
|
|
ec23a532f6 | ||
|
|
8a800062dd | ||
|
|
cf14144d5b | ||
|
|
28e7a806b4 | ||
|
|
a0e56aa4cf | ||
|
|
b3e3b73159 | ||
|
|
046452fc56 | ||
|
|
e77b8785ff | ||
|
|
061fc5a24d | ||
|
|
cb8c2cb450 | ||
|
|
98d661eda1 | ||
|
|
8ddbc9c427 | ||
|
|
5902cd5c28 | ||
|
|
ce2f6ddadd | ||
|
|
cdc5589bcf | ||
|
|
833534bdaa | ||
|
|
8d30fea63b | ||
|
|
7d06c5b37a | ||
|
|
dd95468d74 | ||
|
|
478bd31dc7 | ||
|
|
44b1d34cc7 | ||
|
|
d0b0b8070c | ||
|
|
996857b10d | ||
|
|
fd81d7b040 | ||
|
|
267a9448ea | ||
|
|
01e45d656e | ||
|
|
9199b1e520 | ||
|
|
3be22dac99 | ||
|
|
ff895aa8a4 | ||
|
|
c9c4280e6e | ||
|
|
dac9c1e52c | ||
|
|
a7e6ab33a1 | ||
|
|
6c49b87a06 | ||
|
|
29e5bbdcc0 | ||
|
|
4fcb357e2f | ||
|
|
ddb5259464 | ||
|
|
52dfc0cf93 | ||
|
|
ad58d102df | ||
|
|
9847f5ba6c | ||
|
|
5f06be6226 | ||
|
|
a68afbf79a | ||
|
|
bf425884fb | ||
|
|
4430fd89a9 | ||
|
|
7432369162 | ||
|
|
43dc9ed88a | ||
|
|
d413e4a278 | ||
|
|
5c460c9f3b | ||
|
|
cf9237f7d6 | ||
|
|
a0b1d6394a | ||
|
|
c6af1e31fe | ||
|
|
a5ce6a806f | ||
|
|
a59475af1c | ||
|
|
1cc1ac2e68 | ||
|
|
924b80574a | ||
|
|
f3a759c80d | ||
|
|
79ee8543f5 | ||
|
|
9b30dfb474 | ||
|
|
0100e67ebf | ||
|
|
bd419912b5 | ||
|
|
cb85d358d1 | ||
|
|
5b114c2412 | ||
|
|
c25b027de4 | ||
|
|
8595dd7d99 | ||
|
|
61a90e2cfb | ||
|
|
593508df22 | ||
|
|
1f3505f371 | ||
|
|
679e80a7c3 | ||
|
|
ebdefb5acd | ||
|
|
e36e1cf282 | ||
|
|
fef5bde0c7 | ||
|
|
dc00879419 | ||
|
|
bae488fd97 | ||
|
|
0a8c1df968 | ||
|
|
4c49558120 | ||
|
|
750f91e339 | ||
|
|
d24b5d21b8 | ||
|
|
9dbfde1a4c | ||
|
|
7f229b0fe8 | ||
|
|
920c2024be | ||
|
|
2a0f391113 | ||
|
|
c3b770ef17 | ||
|
|
a14fbe865f | ||
|
|
ae0bb838bf | ||
|
|
587eb48f61 | ||
|
|
0e0de638d4 | ||
|
|
fd92d86954 | ||
|
|
c41f5355fd | ||
|
|
ea9de4feaf | ||
|
|
114737db41 | ||
|
|
bf278af950 | ||
|
|
e1b231882e | ||
|
|
fa04cde25d | ||
|
|
705dd390e9 | ||
|
|
078aa79270 | ||
|
|
a1ad0a3e07 | ||
|
|
858f699750 | ||
|
|
7cf3d9cd94 | ||
|
|
c28e1fa0be | ||
|
|
e9bc8926ab | ||
|
|
4d7204debc | ||
|
|
30ded5e803 | ||
|
|
65a343ce5c | ||
|
|
8841c3e7f9 | ||
|
|
1e4579a076 | ||
|
|
be2721cd67 | ||
|
|
58281520d3 | ||
|
|
58dacfa263 | ||
|
|
ae903082d8 | ||
|
|
9e54fb88f8 | ||
|
|
5859b4cd66 | ||
|
|
8a987afefd | ||
|
|
1a859669eb | ||
|
|
56f2480caa | ||
|
|
0096d063dd | ||
|
|
7c3bb41728 | ||
|
|
99ae0c3d31 | ||
|
|
6582536591 | ||
|
|
628d7249b1 | ||
|
|
7eb2fd23c3 | ||
|
|
46961711e4 | ||
|
|
819d475181 | ||
|
|
07030378c8 | ||
|
|
277be165b6 | ||
|
|
1b4de3b64e | ||
|
|
a1d8f8aa4e | ||
|
|
8c3dfe94c7 | ||
|
|
0a9107b602 | ||
|
|
680cab52f3 | ||
|
|
6abb07e61b | ||
|
|
b59c2be12d | ||
|
|
d49d03846f | ||
|
|
b51670cb25 | ||
|
|
487c6c2c7c | ||
|
|
87b8a8e0a0 | ||
|
|
47e0c23e64 | ||
|
|
dd454689e0 | ||
|
|
94872b3ebb | ||
|
|
9ae863d7c4 | ||
|
|
457accf329 | ||
|
|
b9c1ecf65f | ||
|
|
d08b486db0 | ||
|
|
d37d83c5b6 | ||
|
|
d45bba924d | ||
|
|
69f7fbe703 | ||
|
|
4753ba5361 | ||
|
|
ada68ffc71 | ||
|
|
446b1b8d99 | ||
|
|
27ff05607c | ||
|
|
f2558cd379 | ||
|
|
4f76a4ead2 | ||
|
|
7835aec034 | ||
|
|
f4f035682c | ||
|
|
d1f9b5631a | ||
|
|
d92ae6136a | ||
|
|
be633d3872 | ||
|
|
453930ff75 | ||
|
|
b7341d0ab8 | ||
|
|
f814822ca3 | ||
|
|
c3f2c9e84c | ||
|
|
074a760b6a | ||
|
|
931060db7c | ||
|
|
417f988ca0 | ||
|
|
d4c9db7fcf | ||
|
|
04956c19d5 | ||
|
|
b350beafa8 | ||
|
|
37cca00e13 | ||
|
|
e5c50640e3 | ||
|
|
351ac78e4b | ||
|
|
e011d86742 | ||
|
|
f019902f41 | ||
|
|
35c86ad6bf | ||
|
|
6ffc2b2f10 | ||
|
|
ec155bf7ba | ||
|
|
8cad7ee509 | ||
|
|
1f7edfdb3b | ||
|
|
55a354406a | ||
|
|
a9fd2453a4 | ||
|
|
ea0eae467d | ||
|
|
5a5ae9fd16 | ||
|
|
838ccdd7b4 | ||
|
|
cfb1999caf | ||
|
|
36cb84eaaa | ||
|
|
73272b28dd | ||
|
|
aa5ef742f6 | ||
|
|
47d2e235a3 | ||
|
|
576912dd55 | ||
|
|
5b366e592c | ||
|
|
170a9d78e7 | ||
|
|
63b10175bf | ||
|
|
a5fb124e69 | ||
|
|
72d45fb0de | ||
|
|
f754f63f8f | ||
|
|
8cf290c034 | ||
|
|
b408a02ef9 | ||
|
|
67146028bf | ||
|
|
acdb14a10a | ||
|
|
dcd4384d46 | ||
|
|
8348370142 | ||
|
|
6b3cdad877 | ||
|
|
6b40caf63a | ||
|
|
99f596ea19 | ||
|
|
637844269f | ||
|
|
ec5bf8e985 | ||
|
|
4bbc5ab0af | ||
|
|
6cfde29f00 | ||
|
|
c115a887d8 | ||
|
|
4cdb81e822 | ||
|
|
f4f7edcc28 | ||
|
|
ae97d7bcc7 | ||
|
|
5f48a3ab5b | ||
|
|
9db3076a48 | ||
|
|
6eb6a5892d | ||
|
|
0ebcd15a3d | ||
|
|
04acf120d6 | ||
|
|
278799795c | ||
|
|
c47cbb354d | ||
|
|
8ff2125312 | ||
|
|
a69763c6de | ||
|
|
5e32b599d6 | ||
|
|
fd6327ab62 | ||
|
|
732977db27 | ||
|
|
45528bfc6d | ||
|
|
c690049246 | ||
|
|
932f2bbceb | ||
|
|
a7ef177164 | ||
|
|
300965ab10 | ||
|
|
d2e7c9a5df | ||
|
|
ee9c692115 | ||
|
|
de1f0c8a9b | ||
|
|
52a64168d7 | ||
|
|
b571ff8412 | ||
|
|
762319055c | ||
|
|
cd9ccb66ed | ||
|
|
ac64f9e30d | ||
|
|
16123dea45 | ||
|
|
814260f0b6 | ||
|
|
439509b408 | ||
|
|
07f57a1e9b | ||
|
|
0c9ddaccf7 | ||
|
|
b23bb04dac | ||
|
|
a7601c36bd | ||
|
|
1a883ba73e | ||
|
|
2e50b364c4 | ||
|
|
b4b41a47b2 | ||
|
|
5b90a3e21d | ||
|
|
ca83f7e8ef | ||
|
|
337a9d6dd0 | ||
|
|
ddf139a659 | ||
|
|
6b8fe50f50 | ||
|
|
233ab778b6 | ||
|
|
4872af1053 | ||
|
|
0ca1ebf724 | ||
|
|
632479b1ba | ||
|
|
9b81891467 | ||
|
|
7b2e1d90e6 | ||
|
|
6fa6b4d4dc | ||
|
|
6efe6f13a9 | ||
|
|
c254749493 | ||
|
|
fd9f8c90a5 | ||
|
|
0a0761c7e0 | ||
|
|
e9d91175c4 | ||
|
|
0c0166b565 | ||
|
|
7bb7ff9f0f | ||
|
|
c2cd076662 | ||
|
|
a9f73e7384 | ||
|
|
14c7d18bdb | ||
|
|
5787d49e9b | ||
|
|
25150268cd | ||
|
|
f7a1412ec7 | ||
|
|
a424d48447 | ||
|
|
e76e3afa87 | ||
|
|
482fe3eb80 | ||
|
|
4de2afc0c5 | ||
|
|
742003b6f3 | ||
|
|
10b8366219 | ||
|
|
4364c89fd4 | ||
|
|
d11d693b52 | ||
|
|
357fc3a73a | ||
|
|
1051a7fb9b | ||
|
|
0687b0c60e | ||
|
|
fc26be3e24 | ||
|
|
f733859e28 | ||
|
|
a4cac2df81 | ||
|
|
4886b4d52a | ||
|
|
3c5a0ad8c1 | ||
|
|
ac267b3daa | ||
|
|
cb347434d3 | ||
|
|
3a7e3c1986 | ||
|
|
d113c4cf7a | ||
|
|
7a8b534c07 | ||
|
|
73d0356058 | ||
|
|
ee7b2838bc | ||
|
|
6f247f64cd | ||
|
|
0b2fd60308 | ||
|
|
f809124a2e | ||
|
|
586828b375 | ||
|
|
e36150a5ca | ||
|
|
0f8e68d4bf | ||
|
|
c543d0936c | ||
|
|
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 | ||
|
|
2df2d089d7 | ||
|
|
4c0c32c02c | ||
|
|
90b2eb712a | ||
|
|
27f5d981da | ||
|
|
ce9e8e7244 | ||
|
|
a3b17d46ce | ||
|
|
246a7f2082 | ||
|
|
2eba8acc23 | ||
|
|
c81c00f918 | ||
|
|
0ca03be001 | ||
|
|
55ea643974 | ||
|
|
599659495b | ||
|
|
9efea80e43 | ||
|
|
4ccfb5d527 | ||
|
|
4f59407cd0 | ||
|
|
2f2c9aadcb | ||
|
|
d21515d964 | ||
|
|
b28549825d | ||
|
|
14ef7564cd | ||
|
|
f04ce09a7d | ||
|
|
2869755819 | ||
|
|
353035e9ca | ||
|
|
660d227ac7 | ||
|
|
b9dcfef551 | ||
|
|
6b74e358dc | ||
|
|
8094fb30f6 | ||
|
|
f753bb1911 | ||
|
|
67596ca49c | ||
|
|
59da71884e | ||
|
|
5d57086795 | ||
|
|
3be46aa44d | ||
|
|
39a643aff6 | ||
|
|
f8bde236b8 | ||
|
|
0ab9380be3 |
No files matched your search
@@ -0,0 +1,78 @@
|
||||
Language: Cpp
|
||||
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: false
|
||||
#AlignConsecutiveMacros: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
#AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
#BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 100
|
||||
CompactNamespaces: true
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
FixNamespaceComments: true
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: None
|
||||
PenaltyBreakAssignment: 50
|
||||
PenaltyBreakBeforeFirstCallParameter: 0
|
||||
PenaltyBreakComment: 100
|
||||
PenaltyBreakFirstLessLess: 200
|
||||
PenaltyBreakString: 100
|
||||
#PenaltyBreakTemplateDeclaration: 0
|
||||
PenaltyExcessCharacter: 10
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SpaceAfterCStyleCast: false
|
||||
#SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
#SpaceBeforeCpp11BracedList: true
|
||||
#SpaceBeforeCtorInitializerColon: false
|
||||
#SpaceBeforeInheritanceColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
#SpaceBeforeRangeBasedForLoopColon: false
|
||||
#SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 4
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
#Standard: c++17
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
@@ -0,0 +1,265 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
jobs:
|
||||
build:
|
||||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
|
||||
# You can convert this to a matrix build if you need cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: install_dependencies
|
||||
run: |
|
||||
sudo apt-get update -y -qq
|
||||
sudo apt-get install libsdl2-dev
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Configure CMake
|
||||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
|
||||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
|
||||
- name: Build
|
||||
# Build your program with the given configuration
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-LINUX
|
||||
path: ${{github.workspace}}/build/bin
|
||||
- name: Test
|
||||
working-directory: ${{github.workspace}}/build
|
||||
# Execute tests defined by the CMake configuration.
|
||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
||||
run: ctest -C ${{env.BUILD_TYPE}}
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
cache-name: [msys64-cache]
|
||||
env:
|
||||
MSYSTEM: MINGW64
|
||||
FF_SCRIPT_SECTIONS: '0'
|
||||
CONFIGURE_ARGS: '--target-list=x86_64-softmmu --without-default-devices -Ddebug=false -Doptimization=0'
|
||||
TEST_ARGS: '--no-suite qtest'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up MSYS2
|
||||
run: |
|
||||
Write-Output "Acquiring msys2.exe installer at $(Get-Date -Format u)"
|
||||
If ( !(Test-Path -Path msys64\var\cache ) ) {
|
||||
mkdir msys64\var\cache
|
||||
}
|
||||
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe.sig" -outfile "msys2.exe.sig"
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe.sig ) {
|
||||
Write-Output "Cached installer sig" ;
|
||||
if ( ((Get-FileHash msys2.exe.sig).Hash -ne (Get-FileHash msys64\var\cache\msys2.exe.sig).Hash) ) {
|
||||
Write-Output "Mis-matched installer sig, new installer download required" ;
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe.sig ;
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe
|
||||
}
|
||||
} else {
|
||||
Write-Output "Matched installer sig, cached installer still valid"
|
||||
}
|
||||
} else {
|
||||
Write-Output "No cached installer sig, new installer download required" ;
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe
|
||||
}
|
||||
}
|
||||
if ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) {
|
||||
Write-Output "Fetching latest installer" ;
|
||||
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe" -outfile "msys64\var\cache\msys2.exe" ;
|
||||
Copy-Item -Path msys2.exe.sig -Destination msys64\var\cache\msys2.exe.sig
|
||||
} else {
|
||||
Write-Output "Using cached installer"
|
||||
}
|
||||
Write-Output "Invoking msys2.exe installer at $(Get-Date -Format u)"
|
||||
msys64\var\cache\msys2.exe -y
|
||||
((Get-Content -path .\msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path .\msys64\etc\post-install\07-pacman-key.post
|
||||
.\msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
|
||||
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update
|
||||
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update
|
||||
taskkill /F /FI "MODULES eq msys-2.0.dll"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
Write-Output "Installing mingw packages at $(Get-Date -Format u)"
|
||||
.\msys64\usr\bin\bash -lc 'pacman -Sy --noconfirm --needed \
|
||||
bison \
|
||||
diffutils \
|
||||
flex \
|
||||
tar \
|
||||
doxygen \
|
||||
cmake \
|
||||
wget \
|
||||
git \
|
||||
grep \
|
||||
make \
|
||||
rsync \
|
||||
ninja \
|
||||
glib2-devel \
|
||||
patch \
|
||||
sed \
|
||||
mingw-w64-x86_64-cmake \
|
||||
mingw-w64-x86_64-binutils \
|
||||
mingw-w64-x86_64-doxygen \
|
||||
mingw-w64-x86_64-capstone \
|
||||
mingw-w64-x86_64-ccache \
|
||||
mingw-w64-x86_64-curl \
|
||||
mingw-w64-x86_64-cyrus-sasl \
|
||||
mingw-w64-x86_64-dtc \
|
||||
mingw-w64-x86_64-gcc \
|
||||
mingw-w64-x86_64-glib2 \
|
||||
mingw-w64-x86_64-gnutls \
|
||||
mingw-w64-x86_64-gtk3 \
|
||||
mingw-w64-x86_64-libgcrypt \
|
||||
mingw-w64-x86_64-libjpeg-turbo \
|
||||
mingw-w64-x86_64-libnfs \
|
||||
mingw-w64-x86_64-libpng \
|
||||
mingw-w64-x86_64-libssh \
|
||||
mingw-w64-x86_64-libtasn1 \
|
||||
mingw-w64-x86_64-libusb \
|
||||
mingw-w64-x86_64-lzo2 \
|
||||
mingw-w64-x86_64-libslirp \
|
||||
mingw-w64-x86_64-nettle \
|
||||
mingw-w64-x86_64-clang \
|
||||
mingw-w64-x86_64-ninja \
|
||||
mingw-w64-x86_64-pixman \
|
||||
mingw-w64-x86_64-pkgconf \
|
||||
mingw-w64-x86_64-python \
|
||||
mingw-w64-x86_64-SDL2 \
|
||||
mingw-w64-x86_64-SDL2_image \
|
||||
mingw-w64-x86_64-snappy \
|
||||
mingw-w64-x86_64-spice \
|
||||
mingw-w64-x86_64-usbredir \
|
||||
mingw-w64-x86_64-zstd \
|
||||
mingw-w64-x86_64-make'
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
run: |
|
||||
Write-Output "Running build at $(Get-Date -Format u)"
|
||||
$env:CHERE_INVOKING = 'yes' # Preserve the current working directory
|
||||
$env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
|
||||
$env:CCACHE_BASEDIR = "$env:CI_PROJECT_DIR"
|
||||
$env:CCACHE_DIR = "$env:CCACHE_BASEDIR/ccache"
|
||||
$env:CCACHE_MAXSIZE = "500M"
|
||||
$env:CCACHE_DEPEND = 1 # cache misses are too expensive with preprocessor mode
|
||||
$env:CC = "ccache gcc"
|
||||
mkdir build
|
||||
cd build
|
||||
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --zero-stats"
|
||||
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True .. && ninja"
|
||||
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --show-stats"
|
||||
Write-Output "Finished build at $(Get-Date -Format u)"
|
||||
|
||||
|
||||
vsbuild-CLANG:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install pthread:x64-windows
|
||||
vcpkg install pthreads:x64-windows
|
||||
vcpkg install pthread-stubs:x64-windows
|
||||
vcpkg install pthreadpool:x64-windows
|
||||
vcpkg install
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
nmake
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-CLANG
|
||||
path: ${{github.workspace}}/build/bin
|
||||
|
||||
|
||||
|
||||
vsbuild-MSVC:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install pthread:x64-windows
|
||||
vcpkg install pthreads:x64-windows
|
||||
vcpkg install pthread-stubs:x64-windows
|
||||
vcpkg install pthreadpool:x64-windows
|
||||
vcpkg install
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
nmake
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-MSVC
|
||||
path: ${{github.workspace}}/build/bin
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
vsbuild-MSVC-MSBUILD:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install pthread:x64-windows
|
||||
vcpkg install pthreads:x64-windows
|
||||
vcpkg install pthread-stubs:x64-windows
|
||||
vcpkg install pthreadpool:x64-windows
|
||||
vcpkg install
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
msbuild dingusppc.sln
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-MSBUILD
|
||||
path: ${{github.workspace}}/build/bin
|
||||
+25
@@ -1,14 +1,34 @@
|
||||
# Ignore binary files
|
||||
out/
|
||||
vcpkg/
|
||||
*.bin
|
||||
|
||||
# Ignore compiled object files
|
||||
.vs/
|
||||
.vscode/
|
||||
*.o
|
||||
*.out
|
||||
*.obj
|
||||
*.d
|
||||
|
||||
# Ignore CMake system files
|
||||
CMakeFiles
|
||||
cmake_install.cmake
|
||||
|
||||
# Ignore Visual Studio configuration files
|
||||
CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore Visual Studio auto-save recovery folder
|
||||
enc_temp_folder/
|
||||
|
||||
# Ignore CodeLite configuration files
|
||||
*.workspace
|
||||
*.workspace.*
|
||||
compile_commands.json
|
||||
*.session
|
||||
*.tags
|
||||
|
||||
# Ignore generated executables
|
||||
dingusppc
|
||||
@@ -17,8 +37,13 @@ dingusppc.exe
|
||||
# Ignore system files
|
||||
.DS_Store
|
||||
Thumb.db
|
||||
ehthumbs.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
|
||||
+176
-52
@@ -1,90 +1,214 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(dingusppc)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(PlatformGlob)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
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 (NOT WIN32 AND NOT EMSCRIPTEN)
|
||||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package (Threads)
|
||||
endif()
|
||||
|
||||
elseif (WIN32) # 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()
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
message(STATUS "Targeting Emscripten")
|
||||
# loguru tries to include excinfo.h, which is not available under Emscripten.
|
||||
add_compile_definitions(LOGURU_STACKTRACES=0)
|
||||
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")
|
||||
if (NOT EMSCRIPTEN)
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
#add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/libsoundio")
|
||||
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Build Cubeb tests")
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "Build Cubeb tools")
|
||||
|
||||
add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
|
||||
|
||||
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")
|
||||
platform_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)
|
||||
if (APPLE)
|
||||
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
|
||||
list(APPEND SOURCES ${APPLE_SOURCES})
|
||||
endif()
|
||||
|
||||
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)
|
||||
elseif (EMSCRIPTEN)
|
||||
target_link_libraries(dingusppc PRIVATE
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
|
||||
"-gsource-map"
|
||||
# 256 MB max for emulated Mac RAM, plus 32 MB of emulator overhead
|
||||
"-s INITIAL_MEMORY=301989888"
|
||||
"-s MODULARIZE"
|
||||
"-s EXPORT_ES6"
|
||||
"-s EXPORT_NAME=emulator"
|
||||
"-s 'EXTRA_EXPORTED_RUNTIME_METHODS=[\"FS\"]'")
|
||||
else()
|
||||
#target_link_libraries(dingusppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES})
|
||||
target_link_libraries(dingusppc PRIVATE SDL2::SDL2 SDL2::SDL2main cubeb
|
||||
${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
find_library(COCOA_LIBRARY Cocoa)
|
||||
target_link_libraries(dingusppc PRIVATE ${COCOA_LIBRARY})
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES})
|
||||
if (DPPC_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc 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)
|
||||
add_compile_options("-DPPC_BENCHMARKS")
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
|
||||
)
|
||||
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": []
|
||||
}
|
||||
]
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
# DingusPPC
|
||||
|
||||
|
||||
## Developers
|
||||
|
||||
- divingkatae
|
||||
- maximumspatium
|
||||
- joevt
|
||||
- mihaip
|
||||
- kkaisershot
|
||||
|
||||
## NT4/PPC fork
|
||||
|
||||
- Wack0
|
||||
|
||||
## DevOps
|
||||
|
||||
- Waqar144
|
||||
- webspacecreations
|
||||
- leap0x7b
|
||||
- sdkmap
|
||||
- dressupgeekout
|
||||
- kth5
|
||||
- dyharlan
|
||||
- roytam1
|
||||
|
||||
## Testing
|
||||
|
||||
- LagLifeYT
|
||||
|
||||
## Thanks
|
||||
|
||||
- 68kmla
|
||||
- AppleFritter
|
||||
- Archive.org
|
||||
- Bitsavers
|
||||
- Blitter.net
|
||||
- Emaculation
|
||||
- GitHub
|
||||
- PenguinPPC
|
||||
- VirtuallyFun
|
||||
- The makers of Loguru, SDL2, Capstone, and CLI11
|
||||
- The developers of other PowerPC Mac emulators, past and present
|
||||
- All those preserving the software and source code of 68k and PowerPC Macs
|
||||
@@ -6,14 +6,13 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
|
||||
|
||||
## Philosophy of Use
|
||||
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PowerPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs,
|
||||
including those of the 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 Power Mac 6100, 7200, and G3 Beige.
|
||||
|
||||
## Implemented Features
|
||||
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow 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,54 @@ 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, the most complete machines are the Power Mac 6100 (SCSI emulation in progress) and the Power Mac G3 Beige (SCSI + ATA emulation in progress, No ATI Rage acceleration).
|
||||
|
||||
## 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++20 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, Capstone, and SDL2 modules are not included by default.
|
||||
|
||||
For SDL2, Linux users may also have to run:
|
||||
|
||||
```
|
||||
sudo apt install libsdl2-dev
|
||||
```
|
||||
|
||||
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
```
|
||||
mkdir build
|
||||
@@ -47,9 +77,10 @@ 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 will include SDL 2 as a requirement.
|
||||
For Raspbian, you may also need the following command:
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
@@ -58,7 +89,7 @@ emulation. To build the tests, use the following terminal commands:
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DDPPC_BUILD_PPC_TESTS=True ..
|
||||
make testppc
|
||||
```
|
||||
|
||||
@@ -72,5 +103,4 @@ make testppc
|
||||
|
||||
## Compiler Requirements
|
||||
|
||||
- GCC 4.7 or newer (i.e. CodeBlocks 13.12 or newer)
|
||||
- Visual Studio 2013 or newer
|
||||
- Any C++20 compatible compiler
|
||||
@@ -1 +0,0 @@
|
||||
theme: jekyll-theme-minimal
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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>
|
||||
#include <debugger/debugger.h>
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
power_off_reason = po_benchmark_exception;
|
||||
}
|
||||
#endif
|
||||
|
||||
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 */ 0x00005AF0
|
||||
};
|
||||
|
||||
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
|
||||
constexpr uint32_t test_samples = 200;
|
||||
constexpr uint32_t test_iterations = 5;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i, j;
|
||||
|
||||
/* 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, 0x1000 + test_size)) {
|
||||
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, false, tbr_freq);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
|
||||
mmu_write_vmem<uint32_t>(0, i * 4, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
LOG_F(INFO, "Test size: 0x%X", test_size);
|
||||
LOG_F(INFO, "First few bytes:");
|
||||
bool did_lf = false;
|
||||
for (i = 0; i < test_size; i++) {
|
||||
uint8_t val = rand() % 256;
|
||||
mmu_write_vmem<uint8_t>(0, 0x1000+i, val);
|
||||
if (i < 64) {
|
||||
printf("%02x", val);
|
||||
did_lf = false;
|
||||
if (i % 32 == 31) {
|
||||
printf("\n");
|
||||
did_lf = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!did_lf)
|
||||
printf("\n");
|
||||
|
||||
#if 0
|
||||
/* prepare benchmark code execution */
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
enter_debugger();
|
||||
#endif
|
||||
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
uint32_t checksum = ppc_state.gpr[3];
|
||||
|
||||
// run the clock once for cache fill etc.
|
||||
uint64_t overhead = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
if (time_elapsed.count() < overhead)
|
||||
overhead = time_elapsed.count();
|
||||
}
|
||||
LOG_F(INFO, "Overhead Time: %lld ns", overhead);
|
||||
|
||||
for (int theproc = 0; theproc < 2; theproc++) {
|
||||
LOG_F(INFO, "Doing %s", theproc ? "ppc_exec_until" : "ppc_exec");
|
||||
for (i = 0; i < test_iterations; i++) {
|
||||
uint64_t best_sample = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
(theproc) ? ppc_exec_until(0xC4) : ppc_exec();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
if (time_elapsed.count() < best_sample)
|
||||
best_sample = time_elapsed.count();
|
||||
}
|
||||
if (ppc_state.gpr[3] != checksum)
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
best_sample -= overhead;
|
||||
LOG_F(INFO, "(%d) %lld ns, %.4lf MiB/s", i+1, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
|
||||
}
|
||||
}
|
||||
|
||||
delete(grackle_obj);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# Detect platform suffix
|
||||
if (EMSCRIPTEN)
|
||||
set(PLATFORM_SUFFIX "_js$")
|
||||
else()
|
||||
set(PLATFORM_SUFFIX "_sdl|_cubeb$")
|
||||
endif()
|
||||
|
||||
# Function to perform a platform-specific glob
|
||||
function(platform_glob RESULT_VAR)
|
||||
set(PLATFORM_SOURCES)
|
||||
foreach(GLOB_PATTERN ${ARGN})
|
||||
file(GLOB GLOB_RESULT ${GLOB_PATTERN})
|
||||
foreach(FILE_PATH ${GLOB_RESULT})
|
||||
get_filename_component(BASE_NAME ${FILE_PATH} NAME_WE)
|
||||
if("${BASE_NAME}" MATCHES ${PLATFORM_SUFFIX} OR NOT "${BASE_NAME}" MATCHES "_js$|_sdl|_cubeb$")
|
||||
list(APPEND PLATFORM_SOURCES ${FILE_PATH})
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
set(${RESULT_VAR} ${PLATFORM_SOURCES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -0,0 +1,12 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
)
|
||||
|
||||
platform_glob(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(core OBJECT ${SOURCES})
|
||||
if (EMSCRIPTEN)
|
||||
target_link_libraries(core PRIVATE)
|
||||
else()
|
||||
target_link_libraries(core PRIVATE SDL2::SDL2)
|
||||
endif()
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
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__) && (defined(__x86_64__) || defined(__i386__)) // 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) & ((len == sizeof(T) * 8) ? (T)-1 : ((T)1 << len) - 1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void insert_bits(T &old_val, T new_val, int pos, int len) {
|
||||
T mask = ((len == sizeof(T) * 8) ? (T)-1 : ((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));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void clear_bit(T &val, const int bit_num) {
|
||||
val &= ~((T)1 << bit_num);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void set_bit(T &val, const int bit_num) {
|
||||
val |= ((T)1 << bit_num);
|
||||
}
|
||||
|
||||
static inline uint32_t extract_with_wrap_around(uint32_t val, int pos, int size) {
|
||||
return (uint32_t)((((uint64_t)val << 32) | val) >> ((8 - (pos & 3) - size) << 3)) &
|
||||
((1LL << (size << 3)) - 1);
|
||||
}
|
||||
|
||||
#endif // BIT_OPS_H
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/** Poor man's signals & slots mechanism implementation. */
|
||||
|
||||
// Inspired by http://schneegans.github.io/tutorials/2015/09/20/signal-slot
|
||||
|
||||
#ifndef CORE_SIGNAL_H
|
||||
#define CORE_SIGNAL_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
template <typename... Args>
|
||||
class CoreSignal {
|
||||
public:
|
||||
CoreSignal() = default;
|
||||
~CoreSignal() = default;
|
||||
|
||||
// Connects a std::function type slot to the signal.
|
||||
// The return value can be used to disconnect the slot.
|
||||
int connect_func(std::function<void(Args...)> const& slot) const {
|
||||
_slots.insert(std::make_pair(++_current_id, slot));
|
||||
return _current_id;
|
||||
}
|
||||
|
||||
// Connects a class method type slot to the signal.
|
||||
// The return value can be used to disconnect the slot.
|
||||
template <typename T>
|
||||
int connect_method(T *inst, void (T::*func)(Args...)) {
|
||||
return connect_func([=](Args... args) {
|
||||
(inst->*func)(args...);
|
||||
});
|
||||
}
|
||||
|
||||
// Calls all connected slots.
|
||||
void emit(Args... args) {
|
||||
if (!_is_enabled) {
|
||||
return;
|
||||
}
|
||||
for (auto const& it : _slots) {
|
||||
it.second(args...);
|
||||
}
|
||||
}
|
||||
|
||||
void disconnect(int id) {
|
||||
_slots.erase(id);
|
||||
}
|
||||
|
||||
void disconnect_all() {
|
||||
_slots.clear();
|
||||
}
|
||||
|
||||
void disable() {
|
||||
_is_enabled = false;
|
||||
}
|
||||
|
||||
void enable() {
|
||||
_is_enabled = true;
|
||||
}
|
||||
|
||||
bool is_enabled() {
|
||||
return _is_enabled;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::map<int, std::function<void(Args...)>> _slots;
|
||||
mutable unsigned int _current_id { 0 };
|
||||
mutable bool _is_enabled { true };
|
||||
};
|
||||
|
||||
#endif // CORE_SIGNAL_H
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 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 <core/coresignal.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class WindowEvent {
|
||||
public:
|
||||
WindowEvent() = default;
|
||||
~WindowEvent() = default;
|
||||
|
||||
uint16_t sub_type;
|
||||
uint32_t window_id;
|
||||
};
|
||||
|
||||
enum : uint16_t {
|
||||
// Standard SDL window event types are uint8_t's, we add our own custom
|
||||
// events after that.
|
||||
WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
|
||||
};
|
||||
|
||||
enum : uint32_t {
|
||||
MOUSE_EVENT_MOTION = 1 << 0,
|
||||
MOUSE_EVENT_BUTTON = 1 << 1,
|
||||
KEYBOARD_EVENT_DOWN = 1 << 0,
|
||||
KEYBOARD_EVENT_UP = 1 << 1,
|
||||
GAMEPAD_EVENT_DOWN = 1 << 0,
|
||||
GAMEPAD_EVENT_UP = 1 << 1,
|
||||
};
|
||||
|
||||
class MouseEvent {
|
||||
public:
|
||||
MouseEvent() = default;
|
||||
~MouseEvent() = default;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t xrel;
|
||||
uint32_t yrel;
|
||||
uint32_t xabs;
|
||||
uint32_t yabs;
|
||||
uint8_t buttons_state;
|
||||
};
|
||||
|
||||
class KeyboardEvent {
|
||||
public:
|
||||
KeyboardEvent() = default;
|
||||
~KeyboardEvent() = default;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t key;
|
||||
uint16_t keys_state;
|
||||
};
|
||||
|
||||
|
||||
enum KeyboardLocale : uint32_t {
|
||||
Eng_USA = 0,
|
||||
Eng_GBR = 1,
|
||||
Fra_FRA = 10,
|
||||
Deu_DEU = 20,
|
||||
Ita_ITA = 30,
|
||||
Spa_ESP = 40,
|
||||
Jpn_JPN = 80,
|
||||
};
|
||||
|
||||
/* AppleJack bits 3-7 are supported but unused */
|
||||
enum GamepadButton : uint8_t {
|
||||
Red = 14,
|
||||
Green = 15,
|
||||
Yellow = 9,
|
||||
Blue = 8,
|
||||
|
||||
FrontLeft = 0,
|
||||
FrontMiddle = 1,
|
||||
FrontRight = 2,
|
||||
|
||||
LeftTrigger = 17,
|
||||
RightTrigger = 16,
|
||||
|
||||
Up = 10,
|
||||
Down = 13,
|
||||
Left = 11,
|
||||
Right = 12,
|
||||
};
|
||||
|
||||
class GamepadEvent {
|
||||
public:
|
||||
GamepadEvent() = default;
|
||||
~GamepadEvent() = default;
|
||||
|
||||
uint32_t gamepad_id;
|
||||
uint32_t flags;
|
||||
uint8_t button;
|
||||
};
|
||||
|
||||
class EventManager {
|
||||
public:
|
||||
static EventManager* get_instance() {
|
||||
if (!event_manager) {
|
||||
event_manager = new EventManager();
|
||||
}
|
||||
return event_manager;
|
||||
};
|
||||
|
||||
void poll_events(uint32_t kbd_locale);
|
||||
|
||||
template <typename T>
|
||||
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
|
||||
_window_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_mouse_handler(T *inst, void (T::*func)(const MouseEvent&)) {
|
||||
_mouse_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_keyboard_handler(T* inst, void (T::*func)(const KeyboardEvent&)) {
|
||||
_keyboard_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_gamepad_handler(T* inst, void (T::*func)(const GamepadEvent&)) {
|
||||
_gamepad_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void add_post_handler(T *inst, void (T::*func)()) {
|
||||
_post_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
void disconnect_handlers() {
|
||||
_window_signal.disconnect_all();
|
||||
_mouse_signal.disconnect_all();
|
||||
_keyboard_signal.disconnect_all();
|
||||
_post_signal.disconnect_all();
|
||||
}
|
||||
|
||||
void disable_input_handlers() {
|
||||
_mouse_signal.disable();
|
||||
_keyboard_signal.disable();
|
||||
}
|
||||
|
||||
private:
|
||||
static EventManager* event_manager;
|
||||
EventManager() {}; // private constructor to implement a singleton
|
||||
|
||||
CoreSignal<const WindowEvent&> _window_signal;
|
||||
CoreSignal<const MouseEvent&> _mouse_signal;
|
||||
CoreSignal<const KeyboardEvent&> _keyboard_signal;
|
||||
CoreSignal<const GamepadEvent&> _gamepad_signal;
|
||||
CoreSignal<> _post_signal;
|
||||
|
||||
uint64_t events_captured = 0;
|
||||
uint64_t unhandled_events = 0;
|
||||
uint64_t key_downs = 0;
|
||||
uint64_t key_ups = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
};
|
||||
|
||||
#endif // EVENT_MANAGER_H
|
||||
@@ -0,0 +1,397 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <core/coresignal.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/adb/adbkeyboard.h>
|
||||
#include <loguru.hpp>
|
||||
#include <SDL.h>
|
||||
|
||||
EventManager* EventManager::event_manager;
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
|
||||
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
|
||||
|
||||
void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
events_captured++;
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
power_off_reason = po_quit;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
WindowEvent we{};
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
// Internal shortcuts, intentionally not sent to the host.
|
||||
// Control-G: mouse grab
|
||||
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
toggle_mouse_grab(event.key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-S: scale quality
|
||||
if (event.key.keysym.sym == SDLK_s && SDL_GetModState() & KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = WINDOW_SCALE_QUALITY_TOGGLE;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
|
||||
if (key_code != -1) {
|
||||
KeyboardEvent ke{};
|
||||
ke.key = key_code;
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
key_downs++;
|
||||
} else {
|
||||
ke.flags = KEYBOARD_EVENT_UP;
|
||||
key_ups++;
|
||||
}
|
||||
// Caps Lock is a special case, since it's a toggle key
|
||||
if (ke.key == AdbKey_CapsLock) {
|
||||
ke.flags = SDL_GetModState() & KMOD_CAPS ?
|
||||
KEYBOARD_EVENT_DOWN : KEYBOARD_EVENT_UP;
|
||||
}
|
||||
this->_keyboard_signal.emit(ke);
|
||||
} else {
|
||||
LOG_F(WARNING, "Unknown key %x pressed", event.key.keysym.sym);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION: {
|
||||
MouseEvent me{};
|
||||
me.xrel = event.motion.xrel;
|
||||
me.yrel = event.motion.yrel;
|
||||
me.xabs = event.motion.x;
|
||||
me.yabs = event.motion.y;
|
||||
me.flags = MOUSE_EVENT_MOTION;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
MouseEvent me{};
|
||||
Uint8 adb_button;
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT : adb_button = 0; break;
|
||||
case SDL_BUTTON_MIDDLE : adb_button = 2; break;
|
||||
case SDL_BUTTON_RIGHT : adb_button = 1; break;
|
||||
default : adb_button = event.button.button - 1;
|
||||
}
|
||||
me.buttons_state = (this->buttons_state |= (1 << adb_button));
|
||||
me.xabs = event.button.x;
|
||||
me.yabs = event.button.y;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
MouseEvent me{};
|
||||
Uint8 adb_button;
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT : adb_button = 0; break;
|
||||
case SDL_BUTTON_MIDDLE : adb_button = 2; break;
|
||||
case SDL_BUTTON_RIGHT : adb_button = 1; break;
|
||||
default : adb_button = event.button.button - 1;
|
||||
}
|
||||
me.buttons_state = (this->buttons_state &= ~(1 << adb_button));
|
||||
me.xabs = event.button.x;
|
||||
me.yabs = event.button.y;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN: {
|
||||
GamepadEvent ge{};
|
||||
switch (event.cbutton.button) {
|
||||
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
|
||||
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
|
||||
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
|
||||
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
|
||||
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
|
||||
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
|
||||
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
|
||||
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
|
||||
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
|
||||
}
|
||||
ge.gamepad_id = event.cbutton.which;
|
||||
ge.flags = GAMEPAD_EVENT_DOWN;
|
||||
this->_gamepad_signal.emit(ge);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERBUTTONUP: {
|
||||
GamepadEvent ge{};
|
||||
switch (event.cbutton.button) {
|
||||
case SDL_CONTROLLER_BUTTON_BACK: ge.button = GamepadButton::FrontLeft; break;
|
||||
case SDL_CONTROLLER_BUTTON_GUIDE: ge.button = GamepadButton::FrontMiddle; break;
|
||||
case SDL_CONTROLLER_BUTTON_START: ge.button = GamepadButton::FrontRight; break;
|
||||
case SDL_CONTROLLER_BUTTON_Y: ge.button = GamepadButton::Blue; break;
|
||||
case SDL_CONTROLLER_BUTTON_X: ge.button = GamepadButton::Yellow; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_UP: ge.button = GamepadButton::Up; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_LEFT: ge.button = GamepadButton::Left; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: ge.button = GamepadButton::Right; break;
|
||||
case SDL_CONTROLLER_BUTTON_DPAD_DOWN: ge.button = GamepadButton::Down; break;
|
||||
case SDL_CONTROLLER_BUTTON_A: ge.button = GamepadButton::Red; break;
|
||||
case SDL_CONTROLLER_BUTTON_B: ge.button = GamepadButton::Green; break;
|
||||
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: ge.button = GamepadButton::RightTrigger; break;
|
||||
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: ge.button = GamepadButton::LeftTrigger; break;
|
||||
}
|
||||
ge.gamepad_id = event.cbutton.which;
|
||||
ge.flags = GAMEPAD_EVENT_UP;
|
||||
this->_gamepad_signal.emit(ge);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
}
|
||||
|
||||
// perform post-processing
|
||||
this->_post_signal.emit();
|
||||
}
|
||||
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event, uint32_t kbd_locale)
|
||||
{
|
||||
switch (event.keysym.sym) {
|
||||
case SDLK_a: return AdbKey_A;
|
||||
case SDLK_b: return AdbKey_B;
|
||||
case SDLK_c: return AdbKey_C;
|
||||
case SDLK_d: return AdbKey_D;
|
||||
case SDLK_e: return AdbKey_E;
|
||||
case SDLK_f: return AdbKey_F;
|
||||
case SDLK_g: return AdbKey_G;
|
||||
case SDLK_h: return AdbKey_H;
|
||||
case SDLK_i: return AdbKey_I;
|
||||
case SDLK_j: return AdbKey_J;
|
||||
case SDLK_k: return AdbKey_K;
|
||||
case SDLK_l: return AdbKey_L;
|
||||
case SDLK_m: return AdbKey_M;
|
||||
case SDLK_n: return AdbKey_N;
|
||||
case SDLK_o: return AdbKey_O;
|
||||
case SDLK_p: return AdbKey_P;
|
||||
case SDLK_q: return AdbKey_Q;
|
||||
case SDLK_r: return AdbKey_R;
|
||||
case SDLK_s: return AdbKey_S;
|
||||
case SDLK_t: return AdbKey_T;
|
||||
case SDLK_u: return AdbKey_U;
|
||||
case SDLK_v: return AdbKey_V;
|
||||
case SDLK_w: return AdbKey_W;
|
||||
case SDLK_x: return AdbKey_X;
|
||||
case SDLK_y: return AdbKey_Y;
|
||||
case SDLK_z: return AdbKey_Z;
|
||||
|
||||
case SDLK_1: return AdbKey_1;
|
||||
case SDLK_2: return AdbKey_2;
|
||||
case SDLK_3: return AdbKey_3;
|
||||
case SDLK_4: return AdbKey_4;
|
||||
case SDLK_5: return AdbKey_5;
|
||||
case SDLK_6: return AdbKey_6;
|
||||
case SDLK_7: return AdbKey_7;
|
||||
case SDLK_8: return AdbKey_8;
|
||||
case SDLK_9: return AdbKey_9;
|
||||
case SDLK_0: return AdbKey_0;
|
||||
|
||||
case SDLK_ESCAPE: return AdbKey_Escape;
|
||||
case SDLK_BACKQUOTE: return AdbKey_Grave;
|
||||
case SDLK_MINUS: return AdbKey_Minus;
|
||||
case SDLK_EQUALS: return AdbKey_Equal;
|
||||
case SDLK_LEFTBRACKET: return AdbKey_LeftBracket;
|
||||
case SDLK_RIGHTBRACKET: return AdbKey_RightBracket;
|
||||
case SDLK_BACKSLASH: return AdbKey_Backslash;
|
||||
case SDLK_SEMICOLON: return AdbKey_Semicolon;
|
||||
case SDLK_QUOTE: return AdbKey_Quote;
|
||||
case SDLK_COMMA: return AdbKey_Comma;
|
||||
case SDLK_PERIOD: return AdbKey_Period;
|
||||
case SDLK_SLASH: return AdbKey_Slash;
|
||||
|
||||
// Convert shifted variants to unshifted
|
||||
case SDLK_EXCLAIM: return AdbKey_1;
|
||||
case SDLK_AT: return AdbKey_2;
|
||||
case SDLK_HASH: return AdbKey_3;
|
||||
case SDLK_DOLLAR: return AdbKey_4;
|
||||
case SDLK_UNDERSCORE: return AdbKey_Minus;
|
||||
case SDLK_PLUS: return AdbKey_Equal;
|
||||
case SDLK_COLON: return AdbKey_Semicolon;
|
||||
case SDLK_QUOTEDBL: return AdbKey_Quote;
|
||||
case SDLK_LESS: return AdbKey_Comma;
|
||||
case SDLK_GREATER: return AdbKey_Period;
|
||||
case SDLK_QUESTION: return AdbKey_Slash;
|
||||
|
||||
case SDLK_TAB: return AdbKey_Tab;
|
||||
case SDLK_RETURN: return AdbKey_Return;
|
||||
case SDLK_SPACE: return AdbKey_Space;
|
||||
case SDLK_BACKSPACE: return AdbKey_Delete;
|
||||
|
||||
case SDLK_DELETE: return AdbKey_ForwardDelete;
|
||||
case SDLK_INSERT: return AdbKey_Help;
|
||||
case SDLK_HOME: return AdbKey_Home;
|
||||
case SDLK_HELP: return AdbKey_Home;
|
||||
case SDLK_END: return AdbKey_End;
|
||||
case SDLK_PAGEUP: return AdbKey_PageUp;
|
||||
case SDLK_PAGEDOWN: return AdbKey_PageDown;
|
||||
|
||||
case SDLK_LCTRL: return AdbKey_Control;
|
||||
case SDLK_RCTRL: return AdbKey_Control;
|
||||
case SDLK_LSHIFT: return AdbKey_Shift;
|
||||
case SDLK_RSHIFT: return AdbKey_Shift;
|
||||
case SDLK_LALT: return AdbKey_Option;
|
||||
case SDLK_RALT: return AdbKey_Option;
|
||||
case SDLK_LGUI: return AdbKey_Command;
|
||||
case SDLK_RGUI: return AdbKey_Command;
|
||||
case SDLK_MENU: return AdbKey_Grave;
|
||||
case SDLK_CAPSLOCK: return AdbKey_CapsLock;
|
||||
|
||||
case SDLK_UP: return AdbKey_ArrowUp;
|
||||
case SDLK_DOWN: return AdbKey_ArrowDown;
|
||||
case SDLK_LEFT: return AdbKey_ArrowLeft;
|
||||
case SDLK_RIGHT: return AdbKey_ArrowRight;
|
||||
;
|
||||
case SDLK_KP_0: return AdbKey_Keypad0;
|
||||
case SDLK_KP_1: return AdbKey_Keypad1;
|
||||
case SDLK_KP_2: return AdbKey_Keypad2;
|
||||
case SDLK_KP_3: return AdbKey_Keypad3;
|
||||
case SDLK_KP_4: return AdbKey_Keypad4;
|
||||
case SDLK_KP_5: return AdbKey_Keypad5;
|
||||
case SDLK_KP_6: return AdbKey_Keypad6;
|
||||
case SDLK_KP_7: return AdbKey_Keypad7;
|
||||
case SDLK_KP_9: return AdbKey_Keypad9;
|
||||
case SDLK_KP_8: return AdbKey_Keypad8;
|
||||
case SDLK_KP_PERIOD: return AdbKey_KeypadDecimal;
|
||||
case SDLK_KP_PLUS: return AdbKey_KeypadPlus;
|
||||
case SDLK_KP_MINUS: return AdbKey_KeypadMinus;
|
||||
case SDLK_KP_MULTIPLY: return AdbKey_KeypadMultiply;
|
||||
case SDLK_KP_DIVIDE: return AdbKey_KeypadDivide;
|
||||
case SDLK_KP_ENTER: return AdbKey_KeypadEnter;
|
||||
case SDLK_KP_EQUALS: return AdbKey_KeypadEquals;
|
||||
case SDLK_NUMLOCKCLEAR: return AdbKey_KeypadClear;
|
||||
;
|
||||
case SDLK_F1: return AdbKey_F1;
|
||||
case SDLK_F2: return AdbKey_F2;
|
||||
case SDLK_F3: return AdbKey_F3;
|
||||
case SDLK_F4: return AdbKey_F4;
|
||||
case SDLK_F5: return AdbKey_F5;
|
||||
case SDLK_F6: return AdbKey_F6;
|
||||
case SDLK_F7: return AdbKey_F7;
|
||||
case SDLK_F8: return AdbKey_F8;
|
||||
case SDLK_F9: return AdbKey_F9;
|
||||
case SDLK_F10: return AdbKey_F10;
|
||||
case SDLK_F11: return AdbKey_F11;
|
||||
case SDLK_F12: return AdbKey_F12;
|
||||
case SDLK_PRINTSCREEN: return AdbKey_F13;
|
||||
case SDLK_SCROLLLOCK: return AdbKey_F14;
|
||||
case SDLK_PAUSE: return AdbKey_F15;
|
||||
|
||||
//International keyboard support
|
||||
|
||||
//Japanese keyboard
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
|
||||
if (kbd_locale == Jpn_JPN)
|
||||
return AdbKey_JIS_Yen;
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
|
||||
return AdbKey_JIS_Underscore;
|
||||
case 0XBC:
|
||||
return AdbKey_JIS_KP_Comma;
|
||||
case 0X89:
|
||||
return AdbKey_JIS_Eisu;
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL2):
|
||||
return AdbKey_JIS_Kana;
|
||||
|
||||
//German keyboard
|
||||
case 0XB4: return AdbKey_Slash;
|
||||
case 0X5E: return AdbKey_ISO1;
|
||||
case 0XDF: return AdbKey_Minus; //Eszett
|
||||
case 0XE4: return AdbKey_LeftBracket; //A-umlaut
|
||||
case 0XF6: return AdbKey_Semicolon; //O-umlaut
|
||||
case 0XFC: return AdbKey_LeftBracket; //U-umlaut
|
||||
|
||||
// French keyboard
|
||||
case 0X29: return AdbKey_Minus; // Right parenthesis
|
||||
case 0X43: return AdbKey_KeypadMultiply; // Star/Mu
|
||||
//0XB2 is superscript 2. Which Mac key should this one map to?
|
||||
case 0XF9: return AdbKey_Quote; // U-grave
|
||||
|
||||
// Italian keyboard
|
||||
case 0XE0: return AdbKey_9; // A-grave
|
||||
case 0XE8: return AdbKey_6; // E-grave
|
||||
case 0XEC: return AdbKey_LeftBracket; // I-grave
|
||||
case 0XF2: return AdbKey_KeypadMultiply; // O-grave
|
||||
|
||||
// Spanish keyboard
|
||||
case 0XA1: return AdbKey_Comma; // Inverted question mark
|
||||
case 0XBA: return AdbKey_6; // Backslash
|
||||
case 0XE7: return AdbKey_Slash; // C-cedilla
|
||||
case 0XF1: return AdbKey_Semicolon; // N-tilde
|
||||
case 0X4000002f:
|
||||
return AdbKey_LeftBracket; // Acute
|
||||
case 0X40000034:
|
||||
return AdbKey_Semicolon; // Acute
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void toggle_mouse_grab(const SDL_KeyboardEvent &event) {
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.windowID);
|
||||
if (SDL_GetRelativeMouseMode()) {
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDL_SetWindowTitle(window, "DingusPPC Display");
|
||||
} else {
|
||||
// If the mouse is initially outside the window, move it to the middle,
|
||||
// so that clicks are handled by the window (instead making it lose
|
||||
// focus, at least with macOS hosts).
|
||||
int mouse_x, mouse_y, window_x, window_y, window_width, window_height;
|
||||
SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
|
||||
SDL_GetWindowPosition(window, &window_x, &window_y);
|
||||
SDL_GetWindowSize(window, &window_width, &window_height);
|
||||
if (mouse_x < window_x || mouse_x >= window_x + window_width ||
|
||||
mouse_y < window_y || mouse_y >= window_y + window_height) {
|
||||
SDL_WarpMouseInWindow(window, window_width / 2, window_height / 2);
|
||||
}
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDL_SetWindowTitle(window, "DingusPPC Display (Mouse Grabbed)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 <cstdint>
|
||||
|
||||
#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,158 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/** Timer management system. */
|
||||
|
||||
#include <loguru.hpp>
|
||||
#include "timermanager.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
TimerManager* TimerManager::timer_manager;
|
||||
|
||||
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
{
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + timeout;
|
||||
ti->interval_ns = 0;
|
||||
ti->cb = cb;
|
||||
|
||||
std::shared_ptr<TimerInfo> timer_desc(ti);
|
||||
|
||||
// add new timer to the timer queue
|
||||
this->timer_queue.push(timer_desc);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_immediate_timer(timer_cb cb) {
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now();
|
||||
ti->interval_ns = 0;
|
||||
ti->cb = cb;
|
||||
|
||||
std::shared_ptr<TimerInfo> timer_desc(ti);
|
||||
|
||||
// add new timer to the timer queue
|
||||
this->timer_queue.push(timer_desc);
|
||||
|
||||
// notify listeners about changes in the timer queue
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + delay;
|
||||
ti->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;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb) {
|
||||
return this->add_cyclic_timer(interval, interval, cb);
|
||||
}
|
||||
|
||||
void TimerManager::cancel_timer(uint32_t id)
|
||||
{
|
||||
this->timer_queue.remove_by_id(id);
|
||||
if (!this->cb_active) {
|
||||
this->notify_timer_changes();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t TimerManager::process_timers()
|
||||
{
|
||||
std::shared_ptr<TimerInfo> cur_timer;
|
||||
uint64_t time_now = get_time_now();
|
||||
|
||||
{ // mtx scope
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
if (this->timer_queue.empty()) {
|
||||
return 0ULL;
|
||||
}
|
||||
|
||||
// scan for expired timers
|
||||
cur_timer = this->timer_queue.top();
|
||||
} // ] mtx scope
|
||||
while (cur_timer->timeout_ns <= time_now) {
|
||||
timer_cb cb = cur_timer->cb;
|
||||
|
||||
// re-arm cyclic timers
|
||||
if (cur_timer->interval_ns) {
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
cur_timer->timeout_ns = time_now + cur_timer->interval_ns;
|
||||
this->timer_queue.remove_by_id(cur_timer->id);
|
||||
this->timer_queue.push(cur_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
|
||||
{ // [ mtx scope
|
||||
std::lock_guard<std::recursive_mutex> lk(this->timer_queue.get_mtx());
|
||||
if (this->timer_queue.empty()) {
|
||||
return 0ULL;
|
||||
}
|
||||
|
||||
cur_timer = this->timer_queue.top();
|
||||
} // ] mtx scope
|
||||
}
|
||||
|
||||
// return time slice in nanoseconds until next timer's expiry
|
||||
return cur_timer->timeout_ns - time_now;
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-25 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 <atomic>
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
constexpr auto NS_PER_SEC = 1000000000;
|
||||
constexpr auto USEC_PER_SEC = 1000000;
|
||||
constexpr auto NS_PER_USEC = 1000;
|
||||
constexpr auto NS_PER_MSEC = 1000000;
|
||||
constexpr auto ONE_BILLION_NS = 1000000000;
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
typedef std::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){
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
auto el = this->top();
|
||||
if (el->id == id) {
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
void push(T val)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
std::priority_queue<T, Container, Compare>::push(val);
|
||||
};
|
||||
|
||||
T pop()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lk(mtx);
|
||||
T val = std::priority_queue<T, Container, Compare>::top();
|
||||
std::priority_queue<T, Container, Compare>::pop();
|
||||
return val;
|
||||
};
|
||||
|
||||
std::recursive_mutex& get_mtx()
|
||||
{
|
||||
return mtx;
|
||||
}
|
||||
|
||||
private:
|
||||
std::recursive_mutex mtx;
|
||||
};
|
||||
|
||||
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 std::shared_ptr<TimerInfo>& l, const std::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 std::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_immediate_timer(timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
|
||||
void cancel_timer(uint32_t id);
|
||||
|
||||
uint64_t process_timers();
|
||||
|
||||
private:
|
||||
static TimerManager* timer_manager;
|
||||
TimerManager(){}; // private constructor to implement a singleton
|
||||
|
||||
// timer queue
|
||||
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
|
||||
|
||||
std::function<uint64_t()> get_time_now;
|
||||
std::function<void()> notify_timer_changes;
|
||||
|
||||
std::atomic<uint32_t> id{0};
|
||||
|
||||
// FIXME: Do we need this? It gets written in main thread and read in audio thread.
|
||||
bool cb_active = false; // true if a timer callback is executing
|
||||
};
|
||||
|
||||
#endif // TIMER_MANAGER_H
|
||||
+11
-2
@@ -1,5 +1,14 @@
|
||||
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}/*.h"
|
||||
)
|
||||
|
||||
# The use of volatile is deprecated, but we still need it to avoid function
|
||||
# parameters being clobbered when using setjmp/longjmp.
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(-Wno-deprecated-volatile)
|
||||
endif()
|
||||
|
||||
add_library(cpu_ppc OBJECT ${SOURCES})
|
||||
+546
-683
File diff suppressed because it is too large.
Load diff
+1208
-691
File diff suppressed because it is too large.
Load diff
+9
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,19 +24,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef struct PPCDisasmContext {
|
||||
uint32_t instr_addr;
|
||||
uint32_t instr_code;
|
||||
uint32_t instr_addr;
|
||||
uint32_t instr_code;
|
||||
std::string instr_str;
|
||||
bool simplified; /* true if we should output simplified mnemonics */
|
||||
bool simplified; /* true if we should output simplified mnemonics */
|
||||
std::vector<std::string> regs_in;
|
||||
std::vector<std::string> regs_out;
|
||||
} PPCDisasmContext;
|
||||
|
||||
std::string disassemble_single(PPCDisasmContext *ctx);
|
||||
std::string disassemble_single(PPCDisasmContext* ctx);
|
||||
|
||||
int test_ppc_disasm(void);
|
||||
|
||||
/** sign-extend an integer. */
|
||||
#define SIGNEXT(x, sb) ((x) | (((x) & (1 << (sb))) ? ~((1 << (sb))-1) : 0))
|
||||
#define SIGNEXT(x, sb) ((x) | (((x) & (1 << (sb))) ? ~((1 << (sb)) - 1) : 0))
|
||||
|
||||
#endif /* PPCDISASM_H */
|
||||
+481
-515
File diff suppressed because it is too large.
Load diff
+255
-112
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,157 +21,300 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Handling of low-level PPC exceptions. */
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <loguru.hpp>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type,
|
||||
uint32_t srr1_bits)
|
||||
{
|
||||
grab_exception = true;
|
||||
#ifdef PROFILER
|
||||
exceptions_performed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#endif
|
||||
|
||||
switch(exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0100;
|
||||
break;
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0100;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
if (!(ppc_state.msr & 0x1000)) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0200;
|
||||
break;
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
if (!(ppc_state.msr & MSR::ME)) {
|
||||
/* TODO: handle internal checkstop */
|
||||
}
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0200;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DSI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0300;
|
||||
break;
|
||||
case Except_Type::EXC_DSI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0300;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ISI:
|
||||
case Except_Type::EXC_ISI:
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0400;
|
||||
break;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0400;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0500;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0600;
|
||||
break;
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0600;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0700;
|
||||
break;
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0700;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0800;
|
||||
break;
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFC;
|
||||
ppc_next_instruction_address = 0x0800;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0900;
|
||||
break;
|
||||
case Except_Type::EXC_DECR:
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0900;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0C00;
|
||||
break;
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0C00;
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0D00;
|
||||
break;
|
||||
case Except_Type::EXC_TRACE:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
ppc_next_instruction_address = 0x0D00;
|
||||
break;
|
||||
|
||||
default:
|
||||
//printf("Unknown exception occured: %X\n", exception_type);
|
||||
//exit(-1);
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Unknown exception occurred: %X\n", (unsigned)exception_type);
|
||||
break;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::SRR1] = (ppc_state.msr & 0x0000FF73) | srr1_bits;
|
||||
ppc_state.msr &= 0xFFFB1041;
|
||||
uint32_t old_msr_val = ppc_state.msr;
|
||||
uint32_t new_msr_val = old_msr_val & 0xFFFB1041;
|
||||
/* copy MSR[ILE] to MSR[LE] */
|
||||
ppc_state.msr = (ppc_state.msr & 0xFFFFFFFE) |
|
||||
((ppc_state.msr >> 16) & 1);
|
||||
if (!is_601) {
|
||||
new_msr_val = (new_msr_val & ~MSR::LE) | !!(new_msr_val & MSR::ILE);
|
||||
}
|
||||
// Don't clobber the ppc_next_instruction_address value
|
||||
ppc_msr_did_change(old_msr_val, new_msr_val, false);
|
||||
|
||||
if (ppc_state.msr & 0x40) {
|
||||
if (ppc_state.msr & MSR::IP) {
|
||||
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 && exception_type != Except_Type::EXC_DECR) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type,
|
||||
uint32_t srr1_bits)
|
||||
{
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
std::string exc_descriptor;
|
||||
|
||||
switch(exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
exc_descriptor = "System reset exception occured";
|
||||
break;
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
exc_descriptor = "System reset exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
exc_descriptor = "Machine check exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
exc_descriptor = "Machine check exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DSI:
|
||||
case Except_Type::EXC_ISI:
|
||||
if (ppc_state.spr[SPR::DSISR] & 0x40000000)
|
||||
exc_descriptor = "DSI/ISI exception: unmapped memory access";
|
||||
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
|
||||
exc_descriptor = "DSI/ISI exception: access protection violation";
|
||||
else {
|
||||
if (exception_type == Except_Type::EXC_DSI)
|
||||
exc_descriptor = "DSI exception";
|
||||
else
|
||||
exc_descriptor = "ISI exception";
|
||||
}
|
||||
break;
|
||||
case Except_Type::EXC_DSI:
|
||||
case Except_Type::EXC_ISI:
|
||||
if (ppc_state.spr[SPR::DSISR] & 0x40000000)
|
||||
exc_descriptor = "DSI/ISI exception: unmapped memory access";
|
||||
else if (ppc_state.spr[SPR::DSISR] & 0x08000000)
|
||||
exc_descriptor = "DSI/ISI exception: access protection violation";
|
||||
else {
|
||||
if (exception_type == Except_Type::EXC_DSI)
|
||||
exc_descriptor = "DSI exception";
|
||||
else
|
||||
exc_descriptor = "ISI exception";
|
||||
}
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
exc_descriptor = "External interrupt exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
exc_descriptor = "External interrupt exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
exc_descriptor = "Alignment exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
exc_descriptor = "Alignment exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
exc_descriptor = "Program exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
exc_descriptor = "Program exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
exc_descriptor = "Floating-Point unavailable exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
exc_descriptor = "Floating-Point unavailable exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
exc_descriptor = "Decrementer exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_DECR:
|
||||
exc_descriptor = "Decrementer exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
exc_descriptor = "Syscall exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
exc_descriptor = "Syscall exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occured";
|
||||
break;
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occurred";
|
||||
break;
|
||||
}
|
||||
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception(uint32_t opcode) {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, opcode);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (opcode & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
case 0xa8000000: // lha
|
||||
case 0xb0000000: // sth
|
||||
case 0xb8000000: // lmw
|
||||
case 0xc0000000: // lfs
|
||||
case 0xc8000000: // lfd
|
||||
case 0xd0000000: // stfs
|
||||
case 0xd8000000: // stfd
|
||||
case 0x84000000: // lwzu
|
||||
case 0x94000000: // stwu
|
||||
case 0xa4000000: // lhzu
|
||||
case 0xac000000: // lhau
|
||||
case 0xb4000000: // sthu
|
||||
case 0xbc000000: // stmw
|
||||
case 0xc4000000: // lfsu
|
||||
case 0xcc000000: // lfdu
|
||||
case 0xd4000000: // stfsu
|
||||
case 0xdc000000: // stfdu
|
||||
// indirect with immediate index
|
||||
dsisr = ((opcode >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((opcode >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
break;
|
||||
case 0x7c000000:
|
||||
switch (opcode & 0xfc0007ff) {
|
||||
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
|
||||
case 0x7c0002aa: // lwax (64-bit only)
|
||||
case 0x7c00042a: // lswx
|
||||
case 0x7c0004aa: // lswi
|
||||
case 0x7c00052a: // stswx
|
||||
case 0x7c0005aa: // stswi
|
||||
case 0x7c0002ea: // lwaux (64 bit only)
|
||||
case 0x7c00012c: // stwcx
|
||||
case 0x7c00042c: // lwbrx
|
||||
case 0x7c00052c: // stwbrx
|
||||
case 0x7c00062c: // lhbrx
|
||||
case 0x7c00072c: // sthbrx
|
||||
case 0x7c00026c: // eciwx // MPC7451
|
||||
case 0x7c00036c: // ecowx // MPC7451
|
||||
case 0x7c00002e: // lwzx
|
||||
case 0x7c00012e: // stwx
|
||||
case 0x7c00022e: // lhzx
|
||||
case 0x7c0002ae: // lhax
|
||||
case 0x7c00032e: // sthx
|
||||
case 0x7c00042e: // lfsx
|
||||
case 0x7c0004ae: // lfdx
|
||||
case 0x7c00052e: // stfsx
|
||||
case 0x7c0005ae: // stfdx
|
||||
case 0x7c00006e: // lwzux
|
||||
case 0x7c00016e: // stwux
|
||||
case 0x7c00026e: // lhzux
|
||||
case 0x7c0002ee: // lhaux
|
||||
case 0x7c00036e: // sthux
|
||||
case 0x7c00046e: // lfsux
|
||||
case 0x7c0004ee: // lfdux
|
||||
case 0x7c00056e: // stfsux
|
||||
case 0x7c0005ee: // stfdux
|
||||
indirect_with_index:
|
||||
dsisr = ((opcode << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((opcode << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((opcode << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
break;
|
||||
case 0x7c0007ec:
|
||||
if ((opcode & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
goto unexpected_instruction;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
opcode);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((opcode >> 16) & 0x000003e0);
|
||||
|
||||
if ((opcode & 0xfc000000) == 0xb8000000) { // lmw
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((opcode & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((opcode & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((opcode >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
ppc_state.spr[SPR::DAR] = ea;
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
+826
-745
File diff suppressed because it is too large.
Load diff
+1201
-1218
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PPC_MACROS_H
|
||||
#define PPC_MACROS_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsdauimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsasimm(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssauimm(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfd_regsauimm(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_da(opcode)\
|
||||
int reg_d = (opcode >> 21) & 31;\
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
|
||||
#define ppc_grab_dab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define ppc_grab_s(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
|
||||
|
||||
#define ppc_grab_regsdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
int reg_b = (opcode >> 11) & 31;\
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssa_stmw(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
unsigned rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash_stswi(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
unsigned rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssb(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_fpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_fpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_grab_regsfpdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define FPR_INT(reg) \
|
||||
ppc_state.fpr[reg].int64_r
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpdia(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsia(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regsfpsiab(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t val_reg_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t val_reg_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsfpsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
double db_test_a = GET_FPR(reg_a); \
|
||||
double db_test_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b);
|
||||
|
||||
#define ppc_grab_regsfpdac(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_c = (opcode >> 6) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_grab_regsfpdabc(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
int reg_c = (opcode >> 6) & 31; \
|
||||
double val_reg_a = GET_FPR(reg_a); \
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
+1398
-425
File diff suppressed because it is too large.
Load diff
+102
-25
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,43 +19,120 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
/** @file PowerPC Memory Management Unit definitions. */
|
||||
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
class MMIODevice;
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
//#define MMU_INTEGRITY_CHECKS
|
||||
|
||||
/** generic PowerPC BAT descriptor (MMU internal state) */
|
||||
typedef struct PPC_BAT_entry {
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t lo_mask; /* mask for low-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
bool valid; /* BAT entry valid for MPC601 */
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t hi_mask; /* mask for high-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
} PPC_BAT_entry;
|
||||
|
||||
/** Block address translation types. */
|
||||
enum BATType : int {
|
||||
IBAT,
|
||||
DBAT
|
||||
};
|
||||
|
||||
extern void ibat_update(uint32_t bat_reg);
|
||||
extern void dbat_update(uint32_t bat_reg);
|
||||
/** TLB types. */
|
||||
enum TLBType : int {
|
||||
ITLB,
|
||||
DTLB
|
||||
};
|
||||
|
||||
extern uint8_t *mmu_get_dma_mem(uint32_t addr, uint32_t size);
|
||||
/** Result of the block address translation. */
|
||||
typedef struct BATResult {
|
||||
bool hit;
|
||||
uint8_t prot;
|
||||
uint32_t phys;
|
||||
} BATResult;
|
||||
|
||||
/** Result of the page address translation. */
|
||||
typedef struct PATResult {
|
||||
uint32_t phys;
|
||||
uint8_t prot;
|
||||
uint8_t pte_c_status; // status of the C bit of the PTE
|
||||
} PATResult;
|
||||
|
||||
/** DMA memory mapping result. */
|
||||
typedef struct MapDmaResult {
|
||||
uint32_t type;
|
||||
bool is_writable;
|
||||
// for memory regions
|
||||
uint8_t* host_va;
|
||||
// for MMIO regions
|
||||
MMIODevice* dev_obj;
|
||||
uint32_t dev_base;
|
||||
} MapDmaResult;
|
||||
|
||||
constexpr uint32_t PPC_PAGE_SIZE_BITS = 12;
|
||||
constexpr uint32_t PPC_PAGE_SIZE = (1 << PPC_PAGE_SIZE_BITS);
|
||||
constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
|
||||
constexpr uint32_t TLB_SIZE = 4096;
|
||||
constexpr uint32_t TLB2_WAYS = 4;
|
||||
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
struct { // for memory pages
|
||||
int64_t host_va_offs_r;
|
||||
int64_t host_va_offs_w;
|
||||
};
|
||||
struct { // for MMIO pages
|
||||
AddressMapEntry* rgn_desc;
|
||||
int64_t dev_base_va;
|
||||
};
|
||||
};
|
||||
uint32_t phys_tag;
|
||||
uint32_t reserved;
|
||||
} 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 MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio);
|
||||
|
||||
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 void mem_write_byte(uint32_t addr, uint8_t value);
|
||||
extern void mem_write_word(uint32_t addr, uint16_t value);
|
||||
extern void mem_write_dword(uint32_t addr, uint32_t value);
|
||||
extern void mem_write_qword(uint32_t addr, uint64_t value);
|
||||
extern uint8_t mem_grab_byte(uint32_t addr);
|
||||
extern uint16_t mem_grab_word(uint32_t addr);
|
||||
extern uint32_t mem_grab_dword(uint32_t addr);
|
||||
extern uint64_t mem_grab_qword(uint32_t addr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
extern void mem_write_dbg(uint32_t virt_addr, uint64_t value, int size);
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
|
||||
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
|
||||
|
||||
#endif // PPCMEMORY_H
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t opcode, uint32_t guest_va);
|
||||
template <class T>
|
||||
extern void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value);
|
||||
|
||||
#endif // PPCMMU_H
|
||||
+1709
-2105
File diff suppressed because it is too large.
Load diff
Regular → Executable
+180
-44
@@ -1,3 +1,5 @@
|
||||
import re
|
||||
|
||||
def gen_ppc_opcode(opc_str, imm):
|
||||
if opc_str == "ADD":
|
||||
return (0x1F << 26) + (3 << 21) + (3 << 16) + (4 << 11) + (0x10A << 1)
|
||||
@@ -99,6 +101,96 @@ 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) + (0 << 16) + (4 << 11) + (0x108 << 1)
|
||||
elif opc_str == "FABS.":
|
||||
return (0x3F << 26) + (3 << 21) + (0 << 16) + (4 << 11) + (0x108 << 1) + 1
|
||||
elif opc_str == "FADD":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1)
|
||||
elif opc_str == "FADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x15 << 1) + 1
|
||||
elif opc_str == "FCMPO":
|
||||
return (0x3F << 26) + (4 << 21) + (4 << 16) + (5 << 11) + (0x20 << 1)
|
||||
elif opc_str == "FCMPU":
|
||||
return (0x3F << 26) + (4 << 21) + (4 << 16) + (5 << 11)
|
||||
elif opc_str == "FCTIW":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xE << 1)
|
||||
elif opc_str == "FCTIW.":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xE << 1) + 1
|
||||
elif opc_str == "FCTIWZ":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xF << 1)
|
||||
elif opc_str == "FCTIWZ.":
|
||||
return (0x3F << 26) + (0 << 16) + (4 << 11) + (0xF << 1) + 1
|
||||
elif opc_str == "FDIV":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIV.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FDIVS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1)
|
||||
elif opc_str == "FDIVS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x12 << 1) + 1
|
||||
elif opc_str == "FMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1)
|
||||
elif opc_str == "FMADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1D << 1) + 1
|
||||
elif opc_str == "FMUL":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMUL.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1) + 1
|
||||
elif opc_str == "FMULS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (6 << 6) + (0x19 << 1)
|
||||
elif opc_str == "FMULS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (6 << 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 == "FMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FMSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1)
|
||||
elif opc_str == "FMSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1C << 1) + 1
|
||||
elif opc_str == "FNMADD":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADD.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMADDS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1)
|
||||
elif opc_str == "FNMADDS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1F << 1) + 1
|
||||
elif opc_str == "FNMSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1)
|
||||
elif opc_str == "FNMSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1) + 1
|
||||
elif opc_str == "FNMSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1)
|
||||
elif opc_str == "FNMSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (6 << 6) + (0x1E << 1) + 1
|
||||
elif opc_str == "FRES":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 11) + (0x18 << 1)
|
||||
elif opc_str == "FSUB":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUB.":
|
||||
return (0x3F << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1) + 1
|
||||
elif opc_str == "FSUBS":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 11) + (0x14 << 1)
|
||||
elif opc_str == "FSUBS.":
|
||||
return (0x3B << 26) + (3 << 21) + (4 << 16) + (5 << 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,95 @@ 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")
|
||||
|
||||
floatRE = re.compile('^([\w]+\.?) +(?:\((\w+)\) )?:: (?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?(?:(fr[ABCD]) +([^ ]+) \| )?FPSCR: (0x\w+) \| CR: (0x\w+)$')
|
||||
|
||||
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()
|
||||
|
||||
p = floatRE.match(line)
|
||||
if p:
|
||||
opcode = p.group(1).upper();
|
||||
out_file.write(opcode+ ",")
|
||||
out_file.write("0x{:X}".format(gen_ppc_opcode(opcode, 0)))
|
||||
|
||||
if p.group(2) == "RTNI":
|
||||
out_file.write(",round=RNI")
|
||||
elif p.group(2) == "RTN":
|
||||
out_file.write(",round=RTN")
|
||||
elif p.group(2) == "RTZ":
|
||||
out_file.write(",round=RTZ")
|
||||
elif p.group(2) == "RTPI":
|
||||
out_file.write(",round=RPI")
|
||||
elif p.group(2) == "VE":
|
||||
out_file.write(",round=VEN")
|
||||
elif p.group(2) != None:
|
||||
print("Warning: line: [%d] unknown round \"%s\"\n" % (lineno, p.group(2)))
|
||||
|
||||
if p.group(3) != None:
|
||||
out_file.write(",%s=%s" % (p.group(3), p.group(4)))
|
||||
if p.group(5) != None:
|
||||
out_file.write(",%s=%s" % (p.group(5), p.group(6)))
|
||||
if p.group(7) != None:
|
||||
out_file.write(",%s=%s" % (p.group(7), p.group(8)))
|
||||
if p.group(9) != None:
|
||||
out_file.write(",%s=%s" % (p.group(9), p.group(10)))
|
||||
|
||||
out_file.write(",FPSCR=%s" % p.group(11))
|
||||
out_file.write(",CR=%s" % p.group(12))
|
||||
out_file.write("\n")
|
||||
else:
|
||||
print("Warning: line: [%d] \"%s\"\n" % (lineno, line))
|
||||
@@ -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
+260
-80
@@ -1,72 +1,97 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../ppcemu.h"
|
||||
/*
|
||||
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 "../ppcdisasm.h"
|
||||
#include "../ppcemu.h"
|
||||
#include <cfenv>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int ntested; /* number of tested instructions */
|
||||
int nfailed; /* number of failed instructions */
|
||||
int ntested; // number of tested instructions
|
||||
int nfailed; // number of failed instructions
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode)
|
||||
{
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
#if defined(PPC_TESTS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
|
||||
ppc_cur_instruction = opcode;
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set."
|
||||
<< endl;
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
|
||||
nfailed++;
|
||||
}
|
||||
ntested++;
|
||||
}
|
||||
|
||||
void xer_update_test()
|
||||
{
|
||||
xer_ov_test("ADDCO", 0x7C632414);
|
||||
xer_ov_test("ADDCO.", 0x7C632415);
|
||||
xer_ov_test("ADDO", 0x7C632614);
|
||||
xer_ov_test("ADDO.", 0x7C632615);
|
||||
xer_ov_test("ADDEO", 0x7C632514);
|
||||
xer_ov_test("ADDEO.", 0x7C632515);
|
||||
xer_ov_test("ADDMEO", 0x7C6305D4);
|
||||
xer_ov_test("ADDMEO.", 0x7C6305D5);
|
||||
xer_ov_test("ADDZEO", 0x7C630594);
|
||||
xer_ov_test("ADDZEO.", 0x7C630595);
|
||||
xer_ov_test("DIVWO", 0x7C6327D6);
|
||||
xer_ov_test("DIVWO.", 0x7C6327D7);
|
||||
xer_ov_test("DIVWUO", 0x7C632796);
|
||||
xer_ov_test("DIVWUO.", 0x7C632797);
|
||||
xer_ov_test("MULLWO", 0x7C6325D6);
|
||||
xer_ov_test("MULLWO.", 0x7C6325D7);
|
||||
xer_ov_test("NEGO", 0x7C6304D0);
|
||||
xer_ov_test("NEGO.", 0x7C6304D1);
|
||||
xer_ov_test("SUBFO", 0x7C632450);
|
||||
xer_ov_test("SUBFO.", 0x7C632451);
|
||||
xer_ov_test("SUBFCO", 0x7C632410);
|
||||
xer_ov_test("SUBFCO.", 0x7C632411);
|
||||
xer_ov_test("SUBFEO", 0x7C632510);
|
||||
xer_ov_test("SUBFEO.", 0x7C632511);
|
||||
xer_ov_test("SUBFMEO", 0x7C6305D0);
|
||||
void xer_update_test() {
|
||||
xer_ov_test("ADDCO", 0x7C632414);
|
||||
xer_ov_test("ADDCO.", 0x7C632415);
|
||||
xer_ov_test("ADDO", 0x7C632614);
|
||||
xer_ov_test("ADDO.", 0x7C632615);
|
||||
xer_ov_test("ADDEO", 0x7C632514);
|
||||
xer_ov_test("ADDEO.", 0x7C632515);
|
||||
xer_ov_test("ADDMEO", 0x7C6305D4);
|
||||
xer_ov_test("ADDMEO.", 0x7C6305D5);
|
||||
xer_ov_test("ADDZEO", 0x7C630594);
|
||||
xer_ov_test("ADDZEO.", 0x7C630595);
|
||||
xer_ov_test("DIVWO", 0x7C6327D6);
|
||||
xer_ov_test("DIVWO.", 0x7C6327D7);
|
||||
xer_ov_test("DIVWUO", 0x7C632796);
|
||||
xer_ov_test("DIVWUO.", 0x7C632797);
|
||||
xer_ov_test("MULLWO", 0x7C6325D6);
|
||||
xer_ov_test("MULLWO.", 0x7C6325D7);
|
||||
xer_ov_test("NEGO", 0x7C6304D0);
|
||||
xer_ov_test("NEGO.", 0x7C6304D1);
|
||||
xer_ov_test("SUBFO", 0x7C632450);
|
||||
xer_ov_test("SUBFO.", 0x7C632451);
|
||||
xer_ov_test("SUBFCO", 0x7C632410);
|
||||
xer_ov_test("SUBFCO.", 0x7C632411);
|
||||
xer_ov_test("SUBFEO", 0x7C632510);
|
||||
xer_ov_test("SUBFEO.", 0x7C632511);
|
||||
xer_ov_test("SUBFMEO", 0x7C6305D0);
|
||||
xer_ov_test("SUBFMEO.", 0x7C6305D1);
|
||||
xer_ov_test("SUBFZEO", 0x7C630590);
|
||||
xer_ov_test("SUBFZEO", 0x7C630590);
|
||||
xer_ov_test("SUBFZEO.", 0x7C630591);
|
||||
}
|
||||
|
||||
/** testing vehicle */
|
||||
static void read_test_data()
|
||||
{
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
static void read_test_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
uint32_t opcode, dest, src1, src2, check_xer, check_cr;
|
||||
|
||||
ifstream tfstream("ppcinttests.csv");
|
||||
ifstream tfstream("ppcinttests.csv");
|
||||
if (!tfstream.is_open()) {
|
||||
cout << "Could not open tests CSV file. Exiting..." << endl;
|
||||
return;
|
||||
@@ -74,7 +99,7 @@ static void read_test_data()
|
||||
|
||||
lineno = 0;
|
||||
|
||||
while(getline(tfstream, line)) {
|
||||
while (getline(tfstream, line)) {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
@@ -84,7 +109,7 @@ static void read_test_data()
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
while(getline(lnstream, token, ',' )) {
|
||||
while (getline(lnstream, token, ',')) {
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
@@ -93,53 +118,50 @@ static void read_test_data()
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
dest = 0;
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
dest = 0;
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
check_xer = 0;
|
||||
check_cr = 0;
|
||||
|
||||
for (i = 2; i < tokens.size(); i++) {
|
||||
if (tokens[i].rfind("rD=", 0) == 0) {
|
||||
dest = stoul(tokens[i].substr(3), NULL, 16);
|
||||
dest = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("rA=", 0) == 0) {
|
||||
src1 = stoul(tokens[i].substr(3), NULL, 16);
|
||||
src1 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("rB=", 0) == 0) {
|
||||
src2 = stoul(tokens[i].substr(3), NULL, 16);
|
||||
src2 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("XER=", 0) == 0) {
|
||||
check_xer = stoul(tokens[i].substr(4), NULL, 16);
|
||||
check_xer = (uint32_t)stoul(tokens[i].substr(4), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno <<
|
||||
". Exiting..." << endl;
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
ppc_state.gpr[3] = src1;
|
||||
ppc_state.gpr[4] = src2;
|
||||
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
if ((tokens[0].rfind("CMP") && (ppc_state.gpr[3] != dest)) ||
|
||||
(ppc_state.spr[SPR::XER] != check_xer) ||
|
||||
(ppc_state.cr != check_cr)) {
|
||||
cout << "Mismatch: instr=" << tokens[0] << ", src1=0x" << hex << src1
|
||||
<< ", src2=0x" << hex << src2 << endl;
|
||||
cout << "expected: dest=0x" << hex << dest << ", XER=0x" << hex
|
||||
<< check_xer << ", CR=0x" << hex << check_cr << endl;
|
||||
cout << "got: dest=0x" << hex << ppc_state.gpr[3] << ", XER=0x"
|
||||
<< hex << ppc_state.spr[SPR::XER] << ", CR=0x" << hex
|
||||
<< ppc_state.cr << endl;
|
||||
(ppc_state.spr[SPR::XER] != check_xer) || (ppc_state.cr != check_cr)) {
|
||||
cout << "Mismatch: instr=" << tokens[0] << ", src1=0x" << hex << src1 << ", src2=0x"
|
||||
<< hex << src2 << endl;
|
||||
cout << "expected: dest=0x" << hex << dest << ", XER=0x" << hex << check_xer
|
||||
<< ", CR=0x" << hex << check_cr << endl;
|
||||
cout << "got: dest=0x" << hex << ppc_state.gpr[3] << ", XER=0x" << hex
|
||||
<< ppc_state.spr[SPR::XER] << ", CR=0x" << hex << ppc_state.cr << endl;
|
||||
cout << "Test file line #: " << dec << lineno << endl << endl;
|
||||
|
||||
nfailed++;
|
||||
@@ -147,8 +169,159 @@ static void read_test_data()
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
double double_from_string(string str) {
|
||||
if (str == "snan")
|
||||
return std::numeric_limits<double>::signaling_NaN();
|
||||
if (str == "qnan")
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
if (str == "-FLT_MAX")
|
||||
return -std::numeric_limits<float>::max();
|
||||
if (str == "-FLT_MIN")
|
||||
return -std::numeric_limits<float>::min();
|
||||
if (str == "-DBL_MAX")
|
||||
return -std::numeric_limits<double>::max();
|
||||
if (str == "-DBL_MIN")
|
||||
return -std::numeric_limits<double>::min();
|
||||
if (str == "FLT_MIN")
|
||||
return std::numeric_limits<float>::min();
|
||||
if (str == "FLT_MAX")
|
||||
return std::numeric_limits<float>::max();
|
||||
if (str == "DBL_MIN")
|
||||
return std::numeric_limits<double>::min();
|
||||
if (str == "DBL_MAX")
|
||||
return std::numeric_limits<double>::max();
|
||||
return stod(str, NULL);
|
||||
}
|
||||
|
||||
static void read_test_float_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
|
||||
uint32_t opcode, src1, src2, check_cr, check_fpscr;
|
||||
uint64_t dest_64;
|
||||
//float sfp_dest, sfp_src1, sfp_src2, sfp_src3;
|
||||
double 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 = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
check_cr = 0;
|
||||
check_fpscr = 0;
|
||||
dfp_src1 = 0.0;
|
||||
dfp_src2 = 0.0;
|
||||
dfp_src3 = 0.0;
|
||||
dest_64 = 0;
|
||||
|
||||
// switch to default rounding
|
||||
fesetround(FE_TONEAREST);
|
||||
|
||||
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 = double_from_string(tokens[i].substr(4));
|
||||
} else if (tokens[i].rfind("frB=", 0) == 0) {
|
||||
dfp_src2 = double_from_string(tokens[i].substr(4));
|
||||
} else if (tokens[i].rfind("frC=", 0) == 0) {
|
||||
dfp_src3 = double_from_string(tokens[i].substr(4));
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
|
||||
check_fpscr = (uint32_t)stoul(tokens[i].substr(6), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (rounding_mode.compare("RTN") == 0) {
|
||||
update_fpscr(0);
|
||||
} else if (rounding_mode.compare("RTZ") == 0) {
|
||||
update_fpscr(1);
|
||||
} else if (rounding_mode.compare("RPI") == 0) {
|
||||
update_fpscr(2);
|
||||
} else if (rounding_mode.compare("RNI") == 0) {
|
||||
update_fpscr(3);
|
||||
} else if (rounding_mode.compare("VEN") == 0) {
|
||||
update_fpscr(FPSCR::VE);
|
||||
} else {
|
||||
cout << "ILLEGAL ROUNDING METHOD: " << 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 = 0;
|
||||
ppc_state.fpr[4].dbl64_r = dfp_src1;
|
||||
ppc_state.fpr[5].dbl64_r = dfp_src2;
|
||||
ppc_state.fpr[6].dbl64_r = dfp_src3;
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
// switch to default rounding
|
||||
fesetround(FE_TONEAREST);
|
||||
|
||||
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() {
|
||||
is_601 = true;
|
||||
initialize_ppc_opcode_table(); //kludge
|
||||
// MPC601 sets MSR[ME] bit during hard reset / Power-On.
|
||||
// Also set MSR[FP] bit so we can test FPU instructions.
|
||||
ppc_state.msr = (MSR::ME | MSR::IP | MSR::FP);
|
||||
|
||||
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
||||
|
||||
@@ -163,6 +336,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;
|
||||
|
||||
+45
-27
@@ -1,22 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../ppcdisasm.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** testing vehicle */
|
||||
static vector<PPCDisasmContext> read_test_data()
|
||||
{
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
static vector<PPCDisasmContext> read_test_data() {
|
||||
string line, token;
|
||||
int i, lineno;
|
||||
PPCDisasmContext ctx;
|
||||
vector<PPCDisasmContext> tstvec;
|
||||
|
||||
ifstream tfstream("ppcdisasmtest.csv");
|
||||
ifstream tfstream("ppcdisasmtest.csv");
|
||||
if (!tfstream.is_open()) {
|
||||
cout << "Could not open tests CSV file. Exiting..." << endl;
|
||||
return tstvec;
|
||||
@@ -24,18 +44,18 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
|
||||
lineno = 0;
|
||||
|
||||
while(getline(tfstream, line)) {
|
||||
while (getline(tfstream, line)) {
|
||||
lineno++;
|
||||
|
||||
if (line.empty() || !line.rfind("#", 0))
|
||||
continue; // skip empty/comment lines
|
||||
continue; // skip empty/comment lines
|
||||
|
||||
istringstream lnstream(line);
|
||||
|
||||
vector<string> tokens;
|
||||
|
||||
while(getline(lnstream, token, ',' )) {
|
||||
//cout << "Token: " << token << endl;
|
||||
while (getline(lnstream, token, ',')) {
|
||||
// cout << "Token: " << token << endl;
|
||||
tokens.push_back(token);
|
||||
}
|
||||
|
||||
@@ -44,16 +64,16 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
continue;
|
||||
}
|
||||
|
||||
ctx = {0};
|
||||
ctx.instr_addr = stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = stoul(tokens[1], NULL, 16);
|
||||
ctx = {0};
|
||||
ctx.instr_addr = (uint32_t)stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
/* build disassembly string out of comma-separated parts */
|
||||
ostringstream idisasm;
|
||||
|
||||
/* put instruction mnemonic padded with trailing spaces */
|
||||
idisasm << tokens[2];
|
||||
idisasm << setw(8 - tokens[2].length()) << "";
|
||||
idisasm << setw(8 - (int)tokens[2].length()) << " ";
|
||||
|
||||
/* now add comma-separated operands */
|
||||
for (i = 3; i < tokens.size(); i++) {
|
||||
@@ -64,7 +84,7 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
|
||||
ctx.instr_str = idisasm.str();
|
||||
|
||||
//cout << idisasm.str() << endl;
|
||||
// cout << idisasm.str() << endl;
|
||||
|
||||
tstvec.push_back(ctx);
|
||||
}
|
||||
@@ -72,8 +92,7 @@ static vector<PPCDisasmContext> read_test_data()
|
||||
return tstvec;
|
||||
}
|
||||
|
||||
int test_ppc_disasm()
|
||||
{
|
||||
int test_ppc_disasm() {
|
||||
int i, nfailed;
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
@@ -84,7 +103,7 @@ int test_ppc_disasm()
|
||||
nfailed = 0;
|
||||
|
||||
for (i = 0; i < testdata.size(); i++) {
|
||||
ctx = {0};
|
||||
ctx = {0};
|
||||
ctx.instr_addr = testdata[i].instr_addr;
|
||||
ctx.instr_code = testdata[i].instr_code;
|
||||
ctx.simplified = true;
|
||||
@@ -92,14 +111,13 @@ int test_ppc_disasm()
|
||||
std::string disas = disassemble_single(&ctx);
|
||||
|
||||
if (disas != testdata[i].instr_str) {
|
||||
cout << "Mismatch found, expected={" << testdata[i].instr_str <<
|
||||
"}, got={" << disas << "}" << endl;
|
||||
cout << "Mismatch found, expected={" << testdata[i].instr_str << "}, got={" << disas
|
||||
<< "}" << endl;
|
||||
nfailed++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Tested " << testdata.size() << " instructions. Failed: " <<
|
||||
nfailed << "." << endl;
|
||||
cout << "Tested " << testdata.size() << " instructions. Failed: " << nfailed << "." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
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")
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+730
-158
File diff suppressed because it is too large.
Load diff
+39
-2
@@ -1,6 +1,43 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
void enter_debugger(void);
|
||||
#include <memory>
|
||||
|
||||
#endif // DEBUGGER_H_
|
||||
class DppcDebugger {
|
||||
public:
|
||||
static DppcDebugger* get_instance() {
|
||||
if (!debugger_obj) {
|
||||
debugger_obj = std::unique_ptr<DppcDebugger>(new DppcDebugger());
|
||||
}
|
||||
return debugger_obj.get();
|
||||
};
|
||||
|
||||
void enter_debugger();
|
||||
|
||||
private:
|
||||
inline static std::unique_ptr<DppcDebugger> debugger_obj{nullptr};
|
||||
explicit DppcDebugger(); // private constructor to implement a singleton
|
||||
};
|
||||
|
||||
#endif // DEBUGGER_H_
|
||||
+45
-3
@@ -1,6 +1,48 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(PlatformGlob)
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
)
|
||||
|
||||
platform_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/clockgen/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/nubus/*.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}/storage/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/firewire/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/usb/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.h"
|
||||
)
|
||||
|
||||
add_library(devices OBJECT ${SOURCES})
|
||||
target_link_libraries(devices PRIVATE cubeb)
|
||||
if (EMSCRIPTEN)
|
||||
target_link_libraries(devices PRIVATE)
|
||||
else()
|
||||
target_link_libraries(devices PRIVATE cubeb SDL2::SDL2)
|
||||
endif()
|
||||
-485
@@ -1,485 +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/>.
|
||||
*/
|
||||
|
||||
/** ADB bus definitions
|
||||
|
||||
Simulates Apple Desktop Bus (ADB) bus
|
||||
|
||||
*/
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include "devices/adb.h"
|
||||
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
#include <thirdparty/SDL2/include/SDL_keycode.h>
|
||||
#include <thirdparty/SDL2/include/SDL_mouse.h>
|
||||
#include <thirdparty/SDL2/include/SDL_stdinc.h>
|
||||
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ADB_Bus::ADB_Bus() {
|
||||
//set data streams as clear
|
||||
this->adb_mouse_register0 = 0x8080;
|
||||
|
||||
input_stream_len = 0;
|
||||
output_stream_len = 2;
|
||||
|
||||
adb_keybd_register3 = 0x6201;
|
||||
adb_mouse_register3 = 0x6302;
|
||||
|
||||
keyboard_access_no = adb_encoded;
|
||||
mouse_access_no = adb_relative;
|
||||
}
|
||||
|
||||
ADB_Bus::~ADB_Bus() {
|
||||
|
||||
}
|
||||
|
||||
bool ADB_Bus::listen(int device, int reg) {
|
||||
if (device == keyboard_access_no) {
|
||||
if (adb_keybd_listen(reg)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (device == mouse_access_no) {
|
||||
if (adb_mouse_listen(reg)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::talk(int device, int reg, uint16_t value) {
|
||||
//temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::bus_reset() {
|
||||
//temp code
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ADB_Bus::set_addr(int dev_addr, int new_addr) {
|
||||
//temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::flush(int dev_addr) {
|
||||
//temp code
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
if (reg == 3) {
|
||||
output_data_stream[0] = (adb_keybd_register3 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register3 & 0xff);
|
||||
return true;
|
||||
}
|
||||
|
||||
while (SDL_PollEvent(&adb_keybd_evt)) {
|
||||
//Poll our SDL key event for any keystrokes.
|
||||
switch (adb_keybd_evt.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (adb_keybd_evt.key.keysym.sym) {
|
||||
case SDLK_a:
|
||||
ask_key_pressed = 0x00;
|
||||
break;
|
||||
case SDLK_s:
|
||||
ask_key_pressed = 0x01;
|
||||
break;
|
||||
case SDLK_d:
|
||||
ask_key_pressed = 0x02;
|
||||
break;
|
||||
case SDLK_f:
|
||||
ask_key_pressed = 0x03;
|
||||
break;
|
||||
case SDLK_h:
|
||||
ask_key_pressed = 0x04;
|
||||
break;
|
||||
case SDLK_g:
|
||||
ask_key_pressed = 0x05;
|
||||
break;
|
||||
case SDLK_z:
|
||||
ask_key_pressed = 0x06;
|
||||
break;
|
||||
case SDLK_x:
|
||||
ask_key_pressed = 0x07;
|
||||
break;
|
||||
case SDLK_c:
|
||||
ask_key_pressed = 0x08;
|
||||
break;
|
||||
case SDLK_v:
|
||||
ask_key_pressed = 0x09;
|
||||
break;
|
||||
case SDLK_b:
|
||||
ask_key_pressed = 0x0B;
|
||||
break;
|
||||
case SDLK_q:
|
||||
ask_key_pressed = 0x0C;
|
||||
break;
|
||||
case SDLK_w:
|
||||
ask_key_pressed = 0x0D;
|
||||
break;
|
||||
case SDLK_e:
|
||||
ask_key_pressed = 0x0E;
|
||||
break;
|
||||
case SDLK_r:
|
||||
ask_key_pressed = 0x0F;
|
||||
break;
|
||||
case SDLK_y:
|
||||
ask_key_pressed = 0x10;
|
||||
break;
|
||||
case SDLK_t:
|
||||
ask_key_pressed = 0x11;
|
||||
break;
|
||||
case SDLK_1:
|
||||
ask_key_pressed = 0x12;
|
||||
break;
|
||||
case SDLK_2:
|
||||
ask_key_pressed = 0x13;
|
||||
break;
|
||||
case SDLK_3:
|
||||
ask_key_pressed = 0x14;
|
||||
break;
|
||||
case SDLK_4:
|
||||
ask_key_pressed = 0x15;
|
||||
break;
|
||||
case SDLK_6:
|
||||
ask_key_pressed = 0x16;
|
||||
break;
|
||||
case SDLK_5:
|
||||
ask_key_pressed = 0x17;
|
||||
break;
|
||||
case SDLK_EQUALS:
|
||||
ask_key_pressed = 0x18;
|
||||
break;
|
||||
case SDLK_9:
|
||||
ask_key_pressed = 0x19;
|
||||
break;
|
||||
case SDLK_7:
|
||||
ask_key_pressed = 0x1A;
|
||||
break;
|
||||
case SDLK_MINUS:
|
||||
ask_key_pressed = 0x1B;
|
||||
break;
|
||||
case SDLK_8:
|
||||
ask_key_pressed = 0x1C;
|
||||
break;
|
||||
case SDLK_0:
|
||||
ask_key_pressed = 0x1D;
|
||||
break;
|
||||
case SDLK_RIGHTBRACKET:
|
||||
ask_key_pressed = 0x1E;
|
||||
break;
|
||||
case SDLK_o:
|
||||
ask_key_pressed = 0x1F;
|
||||
break;
|
||||
case SDLK_u:
|
||||
ask_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_LEFTBRACKET:
|
||||
ask_key_pressed = 0x21;
|
||||
break;
|
||||
case SDLK_i:
|
||||
ask_key_pressed = 0x22;
|
||||
break;
|
||||
case SDLK_p:
|
||||
ask_key_pressed = 0x23;
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
ask_key_pressed = 0x24;
|
||||
break;
|
||||
case SDLK_l:
|
||||
ask_key_pressed = 0x25;
|
||||
break;
|
||||
case SDLK_j:
|
||||
ask_key_pressed = 0x26;
|
||||
break;
|
||||
case SDLK_QUOTE:
|
||||
ask_key_pressed = 0x27;
|
||||
break;
|
||||
case SDLK_k:
|
||||
ask_key_pressed = 0x28;
|
||||
break;
|
||||
case SDLK_SEMICOLON:
|
||||
ask_key_pressed = 0x29;
|
||||
break;
|
||||
case SDLK_BACKSLASH:
|
||||
ask_key_pressed = 0x2A;
|
||||
break;
|
||||
case SDLK_COMMA:
|
||||
ask_key_pressed = 0x2B;
|
||||
break;
|
||||
case SDLK_SLASH:
|
||||
ask_key_pressed = 0x2C;
|
||||
break;
|
||||
case SDLK_n:
|
||||
ask_key_pressed = 0x2D;
|
||||
break;
|
||||
case SDLK_m:
|
||||
ask_key_pressed = 0x2E;
|
||||
break;
|
||||
case SDLK_PERIOD:
|
||||
ask_key_pressed = 0x2F;
|
||||
break;
|
||||
case SDLK_BACKQUOTE:
|
||||
ask_key_pressed = 0x32;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
ask_key_pressed = 0x35;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
ask_key_pressed = 0x3B;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
ask_key_pressed = 0x3C;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
ask_key_pressed = 0x3D;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
ask_key_pressed = 0x3E;
|
||||
break;
|
||||
case SDLK_KP_PERIOD:
|
||||
ask_key_pressed = 0x41;
|
||||
break;
|
||||
case SDLK_KP_MULTIPLY:
|
||||
ask_key_pressed = 0x43;
|
||||
break;
|
||||
case SDLK_KP_PLUS:
|
||||
ask_key_pressed = 0x45;
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
ask_key_pressed = 0x47;
|
||||
break;
|
||||
case SDLK_KP_DIVIDE:
|
||||
ask_key_pressed = 0x4B;
|
||||
break;
|
||||
case SDLK_KP_ENTER:
|
||||
ask_key_pressed = 0x4C;
|
||||
break;
|
||||
case SDLK_KP_MINUS:
|
||||
ask_key_pressed = 0x4E;
|
||||
break;
|
||||
case SDLK_KP_0:
|
||||
ask_key_pressed = 0x52;
|
||||
break;
|
||||
case SDLK_KP_1:
|
||||
ask_key_pressed = 0x53;
|
||||
break;
|
||||
case SDLK_KP_2:
|
||||
ask_key_pressed = 0x54;
|
||||
break;
|
||||
case SDLK_KP_3:
|
||||
ask_key_pressed = 0x55;
|
||||
break;
|
||||
case SDLK_KP_4:
|
||||
ask_key_pressed = 0x56;
|
||||
break;
|
||||
case SDLK_KP_5:
|
||||
ask_key_pressed = 0x57;
|
||||
break;
|
||||
case SDLK_KP_6:
|
||||
ask_key_pressed = 0x58;
|
||||
break;
|
||||
case SDLK_KP_7:
|
||||
ask_key_pressed = 0x59;
|
||||
break;
|
||||
case SDLK_KP_8:
|
||||
ask_key_pressed = 0x5B;
|
||||
break;
|
||||
case SDLK_KP_9:
|
||||
ask_key_pressed = 0x5C;
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
//ask_key_pressed = 0x33;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x40;
|
||||
break;
|
||||
case SDLK_CAPSLOCK:
|
||||
//ask_key_pressed = 0x39;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x20;
|
||||
break;
|
||||
case SDLK_RALT:
|
||||
case SDLK_RCTRL: //Temp key for Control key
|
||||
//ask_key_pressed = 0x36;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x8;
|
||||
break;
|
||||
case SDLK_LSHIFT:
|
||||
case SDLK_RSHIFT:
|
||||
//ask_key_pressed = 0x38;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x4;
|
||||
break;
|
||||
case SDLK_LALT:
|
||||
//ask_key_pressed = 0x3A;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x2;
|
||||
break;
|
||||
case SDLK_LCTRL: //Temp key for the Command/Apple key
|
||||
//ask_key_pressed = 0x37;
|
||||
confirm_ask_reg_2 = true;
|
||||
mod_key_pressed = 0x1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (adb_keybd_register0 & 0x8000) {
|
||||
adb_keybd_register0 &= 0x7FFF;
|
||||
adb_keybd_register0 &= (ask_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
else if (adb_keybd_register0 & 0x80) {
|
||||
adb_keybd_register0 &= 0xFF7F;
|
||||
adb_keybd_register0 &= (ask_key_pressed);
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
|
||||
//check if mod keys are being pressed
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register0 |= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
if (!(adb_keybd_register0 & 0x8000)) {
|
||||
adb_keybd_register0 |= 0x8000;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
}
|
||||
else if (adb_keybd_register0 & 0x80)
|
||||
adb_keybd_register0 |= 0x0080;
|
||||
output_data_stream[0] = (adb_keybd_register0 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register0 & 0xff);
|
||||
|
||||
if (confirm_ask_reg_2) {
|
||||
adb_keybd_register2 &= (mod_key_pressed << 8);
|
||||
output_data_stream[0] = (adb_keybd_register2 >> 8);
|
||||
output_data_stream[1] = (adb_keybd_register2 & 0xff);
|
||||
confirm_ask_reg_2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((reg != 1)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if ((reg != 0) | (reg != 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (SDL_PollEvent(&adb_mouse_evt)) {
|
||||
if (adb_mouse_evt.motion.x) {
|
||||
this->adb_mouse_register0 &= 0x7F;
|
||||
|
||||
if (adb_mouse_evt.motion.xrel < 0) {
|
||||
if (adb_mouse_evt.motion.xrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F;
|
||||
}
|
||||
else if (adb_mouse_evt.motion.xrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F;
|
||||
}
|
||||
else {
|
||||
this->adb_mouse_register0 |= adb_mouse_evt.motion.xrel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (adb_mouse_evt.motion.y) {
|
||||
this->adb_mouse_register0 &= 0x7F00;
|
||||
|
||||
if (adb_mouse_evt.motion.yrel < 0) {
|
||||
if (adb_mouse_evt.motion.yrel <= -64) {
|
||||
this->adb_mouse_register0 |= 0x7F00;
|
||||
}
|
||||
else if (adb_mouse_evt.motion.yrel >= 63) {
|
||||
this->adb_mouse_register0 |= 0x3F00;
|
||||
}
|
||||
else {
|
||||
this->adb_mouse_register0 |= (adb_mouse_evt.motion.yrel << 8);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (adb_mouse_evt.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
this->adb_mouse_register0 &= 0x7FFF;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
this->adb_mouse_register0 |= 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
if (reg == 0) {
|
||||
output_data_stream[0] = (adb_mouse_register0 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register0 & 0xff);
|
||||
}
|
||||
else if (reg == 3) {
|
||||
output_data_stream[0] = (adb_mouse_register3 >> 8);
|
||||
output_data_stream[1] = (adb_mouse_register3 & 0xff);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t ADB_Bus::get_input_byte(int offset) {
|
||||
return input_data_stream[offset];
|
||||
}
|
||||
|
||||
uint8_t ADB_Bus::get_output_byte(int offset) {
|
||||
return output_data_stream[offset];
|
||||
}
|
||||
|
||||
int ADB_Bus::get_input_len() {
|
||||
return input_stream_len;
|
||||
}
|
||||
|
||||
int ADB_Bus::get_output_len() {
|
||||
return output_stream_len;
|
||||
}
|
||||
@@ -1,86 +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 ADB_H
|
||||
#define ADB_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/SDL2/include/SDL.h>
|
||||
#include <thirdparty/SDL2/include/SDL_events.h>
|
||||
|
||||
enum adb_default_values {
|
||||
adb_reserved0, adb_reserved1, adb_encoded, adb_relative,
|
||||
adb_absolute, adb_reserved5, adb_reserved6, adb_reserved7,
|
||||
adb_other8, adb_other9, adb_other10, adb_other11,
|
||||
adb_other12, adb_other13, adb_other14, adb_other15
|
||||
};
|
||||
|
||||
class ADB_Bus
|
||||
{
|
||||
public:
|
||||
ADB_Bus();
|
||||
~ADB_Bus();
|
||||
|
||||
bool listen(int device, int reg);
|
||||
bool talk(int device, int reg, uint16_t value);
|
||||
bool bus_reset();
|
||||
bool set_addr(int dev_addr, int new_addr);
|
||||
bool flush(int dev_addr);
|
||||
|
||||
bool adb_keybd_listen(int reg);
|
||||
bool adb_mouse_listen(int reg);
|
||||
|
||||
uint8_t get_input_byte(int offset);
|
||||
uint8_t get_output_byte(int offset);
|
||||
|
||||
int get_input_len();
|
||||
int get_output_len();
|
||||
|
||||
private:
|
||||
int keyboard_access_no;
|
||||
int mouse_access_no;
|
||||
|
||||
//Keyboard Variables
|
||||
|
||||
uint16_t adb_keybd_register0;
|
||||
uint16_t adb_keybd_register2;
|
||||
uint16_t adb_keybd_register3;
|
||||
|
||||
SDL_Event adb_keybd_evt;
|
||||
|
||||
uint8_t ask_key_pressed;
|
||||
uint8_t mod_key_pressed;
|
||||
|
||||
bool confirm_ask_reg_2;
|
||||
|
||||
//Mouse Variables
|
||||
SDL_Event adb_mouse_evt;
|
||||
|
||||
uint16_t adb_mouse_register0;
|
||||
uint16_t adb_mouse_register3;
|
||||
|
||||
uint8_t input_data_stream[16]; //temp buffer
|
||||
int input_stream_len;
|
||||
uint8_t output_data_stream[16]; //temp buffer
|
||||
int output_stream_len;
|
||||
};
|
||||
|
||||
#endif /* ADB_H */
|
||||
@@ -1,360 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <atirage.h>
|
||||
#include <cstdint>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "endianswap.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "pcidevice.h"
|
||||
#include "displayid.h"
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id) : PCIDevice("ati-rage")
|
||||
{
|
||||
this->vram_size = 0x200000; /* FIXME: hardcoded VRAM size! */
|
||||
|
||||
/*allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
|
||||
/* configure PCI parameters */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[8], 0x0300005C);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
}
|
||||
|
||||
ATIRage::~ATIRage()
|
||||
{
|
||||
if (this->vram_ptr) {
|
||||
delete this->vram_ptr;
|
||||
}
|
||||
|
||||
delete (this->disp_id);
|
||||
}
|
||||
|
||||
uint32_t ATIRage::size_dep_read(uint8_t *buf, uint32_t size)
|
||||
{
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_LE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_LE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ATI Rage read: invalid size %d", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::size_dep_write(uint8_t *buf, uint32_t value, uint32_t size)
|
||||
{
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_BE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset)
|
||||
{
|
||||
const char* reg_name;
|
||||
|
||||
switch (reg_offset & ~3) {
|
||||
case ATI_CRTC_H_TOTAL_DISP:
|
||||
reg_name = "CRTC_H_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_H_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_H_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_V_TOTAL_DISP:
|
||||
reg_name = "CRTC_V_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_V_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_V_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
reg_name = "CRTC_OFF_PITCH";
|
||||
break;
|
||||
case ATI_CRTC_INT_CNTL:
|
||||
reg_name = "CRTC_INT_CNTL";
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
reg_name = "CRTC_GEN_CNTL";
|
||||
break;
|
||||
case ATI_DSP_CONFIG:
|
||||
reg_name = "DSP_CONFIG";
|
||||
break;
|
||||
case ATI_DSP_ON_OFF:
|
||||
reg_name = "DSP_ON_OFF";
|
||||
break;
|
||||
case ATI_MEM_BUF_CNTL:
|
||||
reg_name = "MEM_BUF_CNTL";
|
||||
break;
|
||||
case ATI_MEM_ADDR_CFG:
|
||||
reg_name = "MEM_ADDR_CFG";
|
||||
break;
|
||||
case ATI_OVR_CLR:
|
||||
reg_name = "OVR_CLR";
|
||||
break;
|
||||
case ATI_OVR_WID_LEFT_RIGHT:
|
||||
reg_name = "OVR_WID_LEFT_RIGHT";
|
||||
break;
|
||||
case ATI_OVR_WID_TOP_BOTTOM:
|
||||
reg_name = "OVR_WID_TOP_BOTTOM";
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
reg_name = "GP_IO";
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
reg_name = "CLOCK_CNTL";
|
||||
break;
|
||||
case ATI_BUS_CNTL:
|
||||
reg_name = "BUS_CNTL";
|
||||
break;
|
||||
case ATI_EXT_MEM_CNTL:
|
||||
reg_name = "EXT_MEM_CNTL";
|
||||
break;
|
||||
case ATI_MEM_CNTL:
|
||||
reg_name = "MEM_CNTL";
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
reg_name = "DAC_REGS";
|
||||
break;
|
||||
case ATI_DAC_CNTL:
|
||||
reg_name = "DAC_CNTL";
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
reg_name = "GEN_TEST_CNTL";
|
||||
break;
|
||||
case ATI_CFG_CHIP_ID:
|
||||
reg_name = "CONFIG_CHIP_ID";
|
||||
break;
|
||||
case ATI_CFG_STAT0:
|
||||
reg_name = "CONFIG_STAT0";
|
||||
break;
|
||||
default:
|
||||
reg_name = "unknown";
|
||||
}
|
||||
|
||||
return reg_name;
|
||||
}
|
||||
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size)
|
||||
{
|
||||
uint32_t res;
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ATI Rage: read I/O reg %s at 0x%X, size=%d, val=0x%X",
|
||||
get_reg_name(offset), offset, size,
|
||||
size_dep_read(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
res = size_dep_read(&this->block_io_regs[offset], size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
size_dep_write(&this->block_io_regs[offset], value, size);
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
||||
gpio_dir = (gpio_val >> 16) & 0x3FFF;
|
||||
WRITE_WORD_LE_A(&this->block_io_regs[ATI_GP_IO],
|
||||
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "ATI Rage: %s register at 0x%X set to 0x%X",
|
||||
get_reg_name(offset), offset & ~3,
|
||||
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
||||
|
||||
res = size_dep_read(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
LOG_F(INFO, "Writing into ATI Rage PCI config space, offset = 0x%X, val=0x%X size=%d",
|
||||
reg_offs, BYTESWAP_32(value), size);
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x10: /* BAR 0 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], 0xFF000000UL);
|
||||
}
|
||||
else {
|
||||
this->aperture_base = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base, 0x01000000, this);
|
||||
}
|
||||
break;
|
||||
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
}
|
||||
break;
|
||||
case CFG_REG_BAR3: /* unimplemented */
|
||||
case CFG_REG_BAR4: /* unimplemented */
|
||||
case CFG_REG_BAR5: /* unimplemented */
|
||||
case CFG_EXP_BASE: /* no expansion ROM */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
default:
|
||||
size_dep_write(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset, uint32_t *p_io_base)
|
||||
{
|
||||
if (!(this->pci_cfg[CFG_REG_CMD] & 1)) {
|
||||
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
|
||||
if (offset < io_base || offset > (io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
*p_io_base = io_base;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t *res)
|
||||
{
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = this->read_reg(offset - io_base, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->write_reg(offset - io_base, value, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
//LOG_F(INFO, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > 0x01000000) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
return size_dep_read(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= 0x7FFC00UL) {
|
||||
/* read from memory-mapped registers */
|
||||
return this->read_reg(offset - 0x7FFC00UL, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
//LOG_F(INFO, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > 0x01000000) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
size_dep_write(this->vram_ptr + offset, value, size);
|
||||
} else if (offset >= 0x7FFC00UL) {
|
||||
/* write to memory-mapped registers */
|
||||
this->write_reg(offset - 0x7FFC00UL, value, size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ATI_RAGE_H
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "pcidevice.h"
|
||||
#include "displayid.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
ATI_PCI_VENDOR_ID = 0x1002,
|
||||
ATI_RAGE_PRO_DEV_ID = 0x4750,
|
||||
ATI_RAGE_GT_DEV_ID = 0x4754,
|
||||
};
|
||||
|
||||
/** Mach registers offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CLONFIG_STAT1 = 0x0094,
|
||||
ATI_CLONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_VGA_WP_SEL = 0x00B4,
|
||||
ATI_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CFG_CHIP_ID = 0x00E0,
|
||||
ATI_CFG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
};
|
||||
|
||||
class ATIRage : public PCIDevice
|
||||
{
|
||||
public:
|
||||
ATIRage(uint16_t dev_id);
|
||||
~ATIRage();
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
bool supports_type(HWCompType type) { return type == HWCompType::MMIO_DEV; };
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) { return true; };
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
/* I/O space access methods */
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t *res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) ;
|
||||
|
||||
protected:
|
||||
uint32_t size_dep_read(uint8_t* buf, uint32_t size);
|
||||
void size_dep_write(uint8_t* buf, uint32_t val, uint32_t size);
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset, uint32_t* p_io_base);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
private:
|
||||
//uint32_t atirage_membuf_regs[9]; /* ATI Rage Memory Buffer Registers */
|
||||
//uint32_t atirage_scratch_regs[4]; /* ATI Rage Scratch Registers */
|
||||
//uint32_t atirage_cmdfifo_regs[3]; /* ATI Rage Command FIFO Registers */
|
||||
//uint32_t atirage_datapath_regs[12]; /* ATI Rage Data Path Registers*/
|
||||
|
||||
uint8_t block_io_regs[256] = { 0 };
|
||||
|
||||
uint8_t pci_cfg[256] = { 0 }; /* PCI configuration space */
|
||||
|
||||
/* Video RAM variables */
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
|
||||
uint32_t aperture_base;
|
||||
|
||||
DisplayID* disp_id;
|
||||
};
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019-20
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "endianswap.h"
|
||||
#include "awacs.h"
|
||||
#include "dbdma.h"
|
||||
#include "machines/machinebase.h"
|
||||
#include "soundserver.h"
|
||||
//#include <thirdparty/libsoundio/soundio/soundio.h>
|
||||
|
||||
static int awac_freqs[8] = {44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350};
|
||||
|
||||
|
||||
AWACDevice::AWACDevice()
|
||||
{
|
||||
this->audio_proc = new AudioProcessor();
|
||||
|
||||
/* register audio processor chip with the I2C bus */
|
||||
I2CBus *i2c_bus = dynamic_cast<I2CBus *>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x45, this->audio_proc);
|
||||
|
||||
this->snd_server = dynamic_cast<SoundServer *>
|
||||
(gMachineObj->get_comp_by_name("SoundServer"));
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AWACDevice::~AWACDevice()
|
||||
{
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
|
||||
delete this->audio_proc;
|
||||
}
|
||||
|
||||
void AWACDevice::set_dma_out(DMAChannel *dma_out_ch)
|
||||
{
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
}
|
||||
|
||||
uint32_t AWACDevice::snd_ctrl_read(uint32_t offset, int size)
|
||||
{
|
||||
switch(offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
return this->snd_ctrl_reg;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
return this->is_busy;
|
||||
case AWAC_CODEC_STATUS_REG:
|
||||
return (AWAC_AVAILABLE << 8) | (AWAC_MAKER_CRYSTAL << 16) |
|
||||
(AWAC_REV_SCREAMER << 20);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AWACDevice::snd_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int subframe, reg_num;
|
||||
uint16_t data;
|
||||
|
||||
switch(offset) {
|
||||
case AWAC_SOUND_CTRL_REG:
|
||||
this->snd_ctrl_reg = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "New sound control value = 0x%X", this->snd_ctrl_reg);
|
||||
break;
|
||||
case AWAC_CODEC_CTRL_REG:
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(INFO, "AWAC subframe = %d, reg = %d, data = %08X\n", subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AWAC: unsupported register at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void convert_data(const uint8_t *in, SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
uint16_t *p_in = (uint16_t *)in;
|
||||
|
||||
for (int i = 0; i < frame_count; i += 2, p_in += 4) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[0]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = BYTESWAP_16(p_in[1]);
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[2]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = BYTESWAP_16(p_in[3]);
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
|
||||
static void insert_silence(SoundIoChannelArea *out_buf, uint32_t frame_count)
|
||||
{
|
||||
for (int i = 0; i < frame_count; i += 2) {
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
*(uint16_t *)(out_buf[0].ptr) = 0;
|
||||
out_buf[0].ptr += out_buf[0].step;
|
||||
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
*(uint16_t *)(out_buf[1].ptr) = 0;
|
||||
out_buf[1].ptr += out_buf[1].step;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static void sound_out_callback(struct SoundIoOutStream *outstream,
|
||||
int frame_count_min, int frame_count_max)
|
||||
{
|
||||
int err, frame_count;
|
||||
uint8_t *p_in;
|
||||
uint32_t buf_len, rem_len, got_len;
|
||||
struct SoundIoChannelArea *areas;
|
||||
DMAChannel *dma_ch = (DMAChannel *)outstream->userdata; /* C API baby! */
|
||||
int n_channels = outstream->layout.channel_count;
|
||||
bool stop = false;
|
||||
|
||||
//if (!dma_ch->is_active()) {
|
||||
// soundio_outstream_clear_buffer(outstream);
|
||||
// soundio_outstream_pause(outstream, true);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (frame_count_max > 512) {
|
||||
frame_count = 512;
|
||||
}
|
||||
else {
|
||||
frame_count = frame_count_max;
|
||||
}
|
||||
|
||||
buf_len = (frame_count * n_channels) << 1;
|
||||
//frame_count = frame_count_max;
|
||||
|
||||
//LOG_F(INFO, "frame_count_min=%d", frame_count_min);
|
||||
//LOG_F(INFO, "frame_count_max=%d", frame_count_max);
|
||||
//LOG_F(INFO, "channel count: %d", n_channels);
|
||||
//LOG_F(INFO, "buf_len: %d", buf_len);
|
||||
|
||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
for (rem_len = buf_len; rem_len > 0; rem_len -= got_len) {
|
||||
if (!dma_ch->get_data(rem_len, &got_len, &p_in)) {
|
||||
//LOG_F(INFO, "SndCallback: got_len = %d", got_len);
|
||||
convert_data(p_in, areas, got_len >> 2);
|
||||
//LOG_F(9, "Converted sound data, len = %d", got_len);
|
||||
} else { /* no more data */
|
||||
//memset(buf, 0, rem_len); /* fill the buffer with silence */
|
||||
//LOG_F(9, "Inserted silence, len = %d", rem_len);
|
||||
|
||||
/* fill the buffer with silence */
|
||||
//LOG_F(ERROR, "rem_len=%d", rem_len);
|
||||
insert_silence(areas, rem_len >> 2);
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = soundio_outstream_end_write(outstream))) {
|
||||
LOG_F(ERROR, "unrecoverable stream error: %s\n", soundio_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
LOG_F(INFO, "pausing result: %s",
|
||||
soundio_strerror(soundio_outstream_pause(outstream, true)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
long AWACDevice::sound_out_callback(cubeb_stream *stream, void *user_data,
|
||||
void const *input_buffer, void *output_buffer,
|
||||
long req_frames)
|
||||
{
|
||||
uint8_t *p_in;
|
||||
int16_t* in_buf, * out_buf;
|
||||
uint32_t got_len;
|
||||
long frames, out_frames;
|
||||
AWACDevice *this_ptr = static_cast<AWACDevice*>(user_data); /* C API baby! */
|
||||
|
||||
if (!this_ptr->dma_out_ch->is_active()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_buf = (int16_t*)output_buffer;
|
||||
|
||||
out_frames = 0;
|
||||
|
||||
while (req_frames > 0) {
|
||||
if (!this_ptr->dma_out_ch->get_data(req_frames << 2, &got_len, &p_in)) {
|
||||
frames = got_len >> 2;
|
||||
|
||||
in_buf = (int16_t*)p_in;
|
||||
|
||||
for (int i = frames; i > 0; i--) {
|
||||
out_buf[0] = BYTESWAP_16(in_buf[0]);
|
||||
out_buf[1] = BYTESWAP_16(in_buf[1]);
|
||||
in_buf += 2;
|
||||
out_buf += 2;
|
||||
}
|
||||
|
||||
req_frames -= frames;
|
||||
out_frames += frames;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out_frames;
|
||||
}
|
||||
|
||||
void status_callback(cubeb_stream *stream, void *user_data, cubeb_state state)
|
||||
{
|
||||
LOG_F(9, "Cubeb status callback fired, status = %d", state);
|
||||
}
|
||||
|
||||
void AWACDevice::open_stream(int sample_rate)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = this->snd_server->open_out_stream(sample_rate, sound_out_callback,
|
||||
status_callback, (void *)this))) {
|
||||
LOG_F(ERROR, "AWAC: unable to open sound output stream: %d", err);
|
||||
this->out_stream_ready = false;
|
||||
} else {
|
||||
this->out_sample_rate = sample_rate;
|
||||
this->out_stream_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_start()
|
||||
{
|
||||
int err;
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else if (this->out_sample_rate != awac_freqs[(this->snd_ctrl_reg >> 8) & 7]) {
|
||||
snd_server->close_out_stream();
|
||||
this->open_stream(awac_freqs[(this->snd_ctrl_reg >> 8) & 7]);
|
||||
} else {
|
||||
LOG_F(ERROR, "AWAC: unpausing attempted!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->out_stream_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err = snd_server->start_out_stream())) {
|
||||
LOG_F(ERROR, "Could not start sound output stream");
|
||||
}
|
||||
}
|
||||
|
||||
void AWACDevice::dma_end()
|
||||
{
|
||||
}
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** AWAC sound devices family definitions.
|
||||
|
||||
Audio Waveform Aplifier and Converter (AWAC) is a family of custom audio
|
||||
chips used in Power Macintosh.
|
||||
*/
|
||||
|
||||
#ifndef AWAC_H
|
||||
#define AWAC_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "i2c.h"
|
||||
#include "dbdma.h"
|
||||
#include "soundserver.h"
|
||||
|
||||
/** AWAC registers offsets. */
|
||||
enum {
|
||||
AWAC_SOUND_CTRL_REG = 0x00,
|
||||
AWAC_CODEC_CTRL_REG = 0x10,
|
||||
AWAC_CODEC_STATUS_REG = 0x20,
|
||||
};
|
||||
|
||||
/** AWAC manufacturer and revision. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Apple source calls this kValidData but doesn't explain
|
||||
what it actually means. It seems like it's used to check
|
||||
if the sound codec is available.
|
||||
*/
|
||||
#define AWAC_AVAILABLE 0x40
|
||||
|
||||
|
||||
/** Audio processor chip (TDA7433) emulation. */
|
||||
class AudioProcessor : public I2CDevice {
|
||||
public:
|
||||
AudioProcessor() = default;
|
||||
~AudioProcessor() = default;
|
||||
|
||||
void start_transaction() { this->pos = 0; };
|
||||
|
||||
bool send_subaddress(uint8_t sub_addr) {
|
||||
if ((sub_addr & 0xF) > 6)
|
||||
return false; /* invalid subaddress -> no acknowledge */
|
||||
|
||||
this->sub_addr = sub_addr & 0xF;
|
||||
this->auto_inc = !!(sub_addr & 0x10);
|
||||
LOG_F(INFO, "TDA7433 subaddress = 0x%X, auto increment = %d",
|
||||
this->sub_addr, this->auto_inc);
|
||||
this->pos++;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool send_byte(uint8_t data) {
|
||||
if (!this->pos) {
|
||||
return send_subaddress(data);
|
||||
} else if (this->sub_addr <= 6) {
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X received", data);
|
||||
this->regs[this->sub_addr] = data;
|
||||
if (this->auto_inc) {
|
||||
this->sub_addr++;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false; /* invalid sub_addr -> no acknowledge */
|
||||
}
|
||||
};
|
||||
|
||||
bool receive_byte(uint8_t *p_data) {
|
||||
*p_data = this->regs[this->sub_addr];
|
||||
LOG_F(INFO, "TDA7433 byte 0x%X sent", *p_data);
|
||||
return true;
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t regs[7]; /* control registers, see TDA7433 datasheet */
|
||||
uint8_t sub_addr;
|
||||
int pos;
|
||||
int auto_inc;
|
||||
};
|
||||
|
||||
|
||||
class AWACDevice : public DMACallback {
|
||||
public:
|
||||
AWACDevice();
|
||||
~AWACDevice();
|
||||
|
||||
void set_dma_out(DMAChannel *dma_out_ch);
|
||||
|
||||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* DMACallback methods */
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
|
||||
protected:
|
||||
void open_stream(int sample_rate);
|
||||
|
||||
private:
|
||||
static long sound_out_callback(cubeb_stream* stream, void* user_data,
|
||||
void const* input_buffer, void* output_buffer,
|
||||
long req_frames);
|
||||
|
||||
uint32_t snd_ctrl_reg = {0};
|
||||
uint16_t control_regs[8] = {0}; /* control registers, each 12-bits wide */
|
||||
uint8_t is_busy = 0;
|
||||
AudioProcessor *audio_proc;
|
||||
|
||||
SoundServer *snd_server;
|
||||
|
||||
bool out_stream_ready;
|
||||
int out_sample_rate;
|
||||
|
||||
DMAChannel *dma_out_ch;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWAC_H */
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Apple Desktop Bus AppleJack controller emulation. */
|
||||
|
||||
#include <devices/common/adb/adbapplejack.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbAppleJack::AdbAppleJack(std::string name) : AdbMouse(name, AdbMouse::TRACKBALL, 2, 7, 300) {
|
||||
EventManager::get_instance()->add_gamepad_handler(this, &AdbAppleJack::event_handler);
|
||||
}
|
||||
|
||||
void AdbAppleJack::event_handler(const GamepadEvent& event) {
|
||||
uint32_t button_bit = 1 << event.button;
|
||||
|
||||
if (event.flags & GAMEPAD_EVENT_DOWN)
|
||||
this->buttons_state |= button_bit;
|
||||
else if (event.flags & GAMEPAD_EVENT_UP)
|
||||
this->buttons_state &= ~button_bit;
|
||||
|
||||
if (button_bit & ((1 << GamepadButton::LeftTrigger) | (1 << GamepadButton::RightTrigger)))
|
||||
this->triggers_changed = true;
|
||||
else
|
||||
this->buttons_changed = true;
|
||||
}
|
||||
|
||||
void AdbAppleJack::reset() {
|
||||
this->AdbMouse::reset();
|
||||
this->buttons_state = 0;
|
||||
this->triggers_changed = false;
|
||||
this->buttons_changed = false;
|
||||
LOG_F(INFO, "%s: reset; in mouse emulation mode", this->name.c_str());
|
||||
}
|
||||
|
||||
bool AdbAppleJack::get_register_0() {
|
||||
bool changed = this->triggers_changed || this->buttons_changed;
|
||||
|
||||
uint8_t mouse_buttons = this->AdbMouse::get_buttons_state();
|
||||
// AppleJack triggers always affect the mouse button bits.
|
||||
mouse_buttons |= (this->buttons_state >> (GamepadButton::LeftTrigger - 0)) & 1;
|
||||
mouse_buttons |= (this->buttons_state >> (GamepadButton::RightTrigger - 1)) & 2;
|
||||
changed |= this->AdbMouse::get_register_0(mouse_buttons, changed);
|
||||
this->triggers_changed = false;
|
||||
|
||||
if (this->dev_handler_id == APPLEJACK_HANDLER_ID && this->buttons_changed) {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
out_buf[2] = ~this->buttons_state >> 8;
|
||||
out_buf[3] = ~this->buttons_state & 0xFF;
|
||||
|
||||
this->host_obj->set_output_count(4);
|
||||
this->buttons_changed = false;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void AdbAppleJack::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case APPLEJACK_HANDLER_ID: // switch over to AppleJack protocol
|
||||
this->dev_handler_id = in_data[1];
|
||||
LOG_F(INFO, "%s: switched to AppleJack mode", this->name.c_str());
|
||||
break;
|
||||
default:
|
||||
this->AdbMouse::set_register_3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbAppleJack_Descriptor = {
|
||||
AdbAppleJack::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbAppleJack, AdbAppleJack_Descriptor);
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Apple Desktop Bus AppleJack controller definitions. */
|
||||
|
||||
#ifndef ADB_APPLEJACK_H
|
||||
#define ADB_APPLEJACK_H
|
||||
|
||||
#include <devices/common/adb/adbmouse.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
enum : uint8_t {
|
||||
APPLEJACK_HANDLER_ID = 0x46,
|
||||
};
|
||||
|
||||
class GamepadEvent;
|
||||
|
||||
class AdbAppleJack : public AdbMouse {
|
||||
public:
|
||||
AdbAppleJack(std::string name);
|
||||
~AdbAppleJack() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AdbAppleJack>(new AdbAppleJack("ADB-APPLEJACK"));
|
||||
}
|
||||
|
||||
void reset() override;
|
||||
void event_handler(const GamepadEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
void set_register_3() override;
|
||||
|
||||
private:
|
||||
uint32_t buttons_state = 0;
|
||||
bool triggers_changed = false;
|
||||
bool buttons_changed = false;
|
||||
};
|
||||
|
||||
#endif // ADB_APPLEJACK_H
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
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 Apple Desktop Bus emulation. */
|
||||
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <sstream>
|
||||
|
||||
AdbBus::AdbBus(std::string name) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::ADB_HOST);
|
||||
this->devices.clear();
|
||||
}
|
||||
|
||||
int AdbBus::device_postinit() {
|
||||
std::string adb_device_list = GET_STR_PROP("adb_devices");
|
||||
if (adb_device_list.empty())
|
||||
return 0;
|
||||
|
||||
std::string adb_device;
|
||||
std::istringstream adb_device_stream(adb_device_list);
|
||||
|
||||
while (getline(adb_device_stream, adb_device, ',')) {
|
||||
std::string dev_name = "Adb" + adb_device;
|
||||
|
||||
if (dev_name == this->name)
|
||||
continue; // don't register a second ADB bus
|
||||
|
||||
if (DeviceRegistry::device_registered(dev_name)) {
|
||||
gMachineObj->add_device(dev_name, DeviceRegistry::get_descriptor(dev_name).m_create_func());
|
||||
} else {
|
||||
LOG_F(WARNING, "Unknown specified ADB device \"%s\"", adb_device.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AdbBus::register_device(AdbDevice* dev_obj) {
|
||||
this->devices.push_back(dev_obj);
|
||||
}
|
||||
|
||||
uint8_t AdbBus::poll() {
|
||||
for (auto dev : this->devices) {
|
||||
uint8_t dev_poll = dev->poll();
|
||||
if (dev_poll) {
|
||||
return dev_poll;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
|
||||
uint8_t dev_addr, dev_reg;
|
||||
|
||||
this->output_count = 0;
|
||||
|
||||
if (!data_size)
|
||||
return ADB_STAT_OK;
|
||||
|
||||
uint8_t cmd_byte = in_data[0];
|
||||
uint8_t cmd = cmd_byte & 0xF;
|
||||
|
||||
if(!cmd) { // SendReset
|
||||
LOG_F(9, "%s: SendReset issued", this->name.c_str());
|
||||
for (auto dev : this->devices)
|
||||
dev->reset();
|
||||
} else if (cmd == 1) { // Flush
|
||||
dev_addr = cmd_byte >> 4;
|
||||
|
||||
LOG_F(9, "%s: Flush issued, dev_addr=0x%X", this->name.c_str(), dev_addr);
|
||||
} else if ((cmd & 0xC) == 8) { // Listen
|
||||
dev_addr = cmd_byte >> 4;
|
||||
dev_reg = cmd_byte & 3;
|
||||
|
||||
LOG_F(9, "%s: Listen R%d issued, dev_addr=0x%X", this->name.c_str(),
|
||||
dev_reg, dev_addr);
|
||||
|
||||
this->input_buf = in_data + 1;
|
||||
this->input_count = data_size - 1;
|
||||
|
||||
for (auto dev : this->devices)
|
||||
dev->listen(dev_addr, dev_reg);
|
||||
} else if ((cmd & 0xC) == 0xC) { // Talk
|
||||
dev_addr = cmd_byte >> 4;
|
||||
dev_reg = cmd_byte & 3;
|
||||
|
||||
LOG_F(9, "%s: Talk R%d issued, dev_addr=0x%X", this->name.c_str(),
|
||||
dev_reg, dev_addr);
|
||||
|
||||
this->got_answer = false;
|
||||
|
||||
for (auto dev : this->devices) {
|
||||
this->got_answer = dev->talk(dev_addr, dev_reg);
|
||||
if (this->got_answer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->got_answer)
|
||||
return ADB_STAT_TIMEOUT;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: unsupported ADB command 0x%X", this->name.c_str(), cmd_byte);
|
||||
}
|
||||
|
||||
return ADB_STAT_OK;
|
||||
}
|
||||
|
||||
static const PropMap AdbBus_Properties = {
|
||||
{"adb_devices", new StrProperty("Mouse,Keyboard")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AdbBus_Descriptor = {
|
||||
AdbBus::create, {}, AdbBus_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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 Apple Desktop Bus definitions. */
|
||||
|
||||
#ifndef ADB_BUS_H
|
||||
#define ADB_BUS_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
constexpr auto ADB_MAX_DATA_SIZE = 8;
|
||||
|
||||
/** ADB status. */
|
||||
enum {
|
||||
ADB_STAT_OK = 0,
|
||||
ADB_STAT_SRQ_ACTIVE = 1 << 0,
|
||||
ADB_STAT_TIMEOUT = 1 << 1,
|
||||
ADB_STAT_AUTOPOLL = 1 << 6,
|
||||
};
|
||||
|
||||
class AdbDevice; // forward declaration to prevent compiler errors
|
||||
|
||||
class AdbBus : public HWComponent {
|
||||
public:
|
||||
AdbBus(std::string name);
|
||||
~AdbBus() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AdbBus>(new AdbBus("ADB-BUS"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void register_device(AdbDevice* dev_obj);
|
||||
uint8_t process_command(const uint8_t* in_data, int data_size);
|
||||
uint8_t get_output_count() { return this->output_count; };
|
||||
|
||||
// Polls devices that have a service request flag set. Returns the talk
|
||||
// command corresponding to the first device that responded with data, or
|
||||
// 0 if no device responded.
|
||||
uint8_t poll();
|
||||
|
||||
// callbacks meant to be called by devices
|
||||
const uint8_t* get_input_buf() { return this->input_buf; };
|
||||
uint8_t* get_output_buf() { return this->output_buf; };
|
||||
uint8_t get_input_count() { return this->input_count; };
|
||||
void set_output_count(uint8_t count) { this->output_count = count; };
|
||||
bool already_answered() { return this->got_answer; };
|
||||
|
||||
private:
|
||||
std::vector<AdbDevice*> devices;
|
||||
|
||||
bool got_answer = false;
|
||||
const uint8_t* input_buf = nullptr;
|
||||
uint8_t output_buf[ADB_MAX_DATA_SIZE] = {};
|
||||
uint8_t input_count = 0;
|
||||
uint8_t output_count = 0;
|
||||
};
|
||||
|
||||
#endif // ADB_BUS_H
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
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 Base class for Apple Desktop Bus devices. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
AdbDevice::AdbDevice(std::string name) {
|
||||
this->set_name(name);
|
||||
this->supports_types(HWCompType::ADB_DEV);
|
||||
}
|
||||
|
||||
int AdbDevice::device_postinit() {
|
||||
// register itself with the ADB host
|
||||
this->host_obj = dynamic_cast<AdbBus*>(gMachineObj->get_comp_by_type(HWCompType::ADB_HOST));
|
||||
this->host_obj->register_device(this);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
uint8_t AdbDevice::poll() {
|
||||
if (!this->srq_flag) {
|
||||
return 0;
|
||||
}
|
||||
bool has_data = this->get_register_0();
|
||||
if (!has_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register 0 in bits 0-1 (both 0)
|
||||
// Talk command in bits 2-3 (both 1)
|
||||
// Device address in bits 4-7
|
||||
return 0xC | (this->my_addr << 4);
|
||||
}
|
||||
|
||||
bool AdbDevice::talk(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
if (dev_addr == this->my_addr && !this->got_collision) {
|
||||
// see if another device already responded to this command
|
||||
if (this->host_obj->already_answered()) {
|
||||
this->got_collision = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(reg_num & 3) {
|
||||
case 0:
|
||||
return this->get_register_0();
|
||||
case 1:
|
||||
return this->get_register_1();
|
||||
case 2:
|
||||
return this->get_register_2();
|
||||
case 3:
|
||||
return this->get_register_3();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
if (dev_addr == this->my_addr) {
|
||||
switch(reg_num & 3) {
|
||||
case 0:
|
||||
this->set_register_0();
|
||||
case 1:
|
||||
this->set_register_1();
|
||||
case 2:
|
||||
this->set_register_2();
|
||||
case 3:
|
||||
this->set_register_3();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AdbDevice::get_register_3() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = this->gen_random_address() | (this->exc_event_flag << 6) |
|
||||
(this->srq_flag << 5);
|
||||
out_buf[1] = this->dev_handler_id;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t AdbDevice::gen_random_address() {
|
||||
return (TimerManager::get_instance()->current_time_ns() + 8) & 0xF;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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 Base class for Apple Desktop Bus devices. */
|
||||
|
||||
#ifndef ADB_DEVICE_H
|
||||
#define ADB_DEVICE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
/** Common ADB device addresses/types. */
|
||||
enum {
|
||||
ADB_ADDR_KBD = 2, // keyboards
|
||||
ADB_ADDR_RELPOS = 3, // relative position devices (mouse)
|
||||
ADB_ADDR_ABSPOS = 4, // absolute position devices (graphic tablets)
|
||||
};
|
||||
|
||||
class AdbBus; // forward declaration to prevent compiler errors
|
||||
|
||||
class AdbDevice : public HWComponent {
|
||||
public:
|
||||
AdbDevice(std::string name);
|
||||
~AdbDevice() = default;
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
virtual void reset() = 0;
|
||||
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual uint8_t get_address() { return this->my_addr; };
|
||||
|
||||
// Attempts to poll the device. Returns the talk command corresponding to
|
||||
// the device if it has data, 0 otherwise.
|
||||
uint8_t poll();
|
||||
|
||||
protected:
|
||||
uint8_t gen_random_address();
|
||||
|
||||
virtual bool get_register_0() { return false; };
|
||||
virtual bool get_register_1() { return false; };
|
||||
virtual bool get_register_2() { return false; };
|
||||
virtual bool get_register_3();
|
||||
|
||||
virtual void set_register_0() {};
|
||||
virtual void set_register_1() {};
|
||||
virtual void set_register_2() {};
|
||||
virtual void set_register_3() {};
|
||||
|
||||
uint8_t exc_event_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t dev_handler_id = 0;
|
||||
bool got_collision = false;
|
||||
|
||||
AdbBus* host_obj = nullptr;
|
||||
};
|
||||
|
||||
#endif // ADB_DEVICE_H
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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 Apple Desktop Bus Keyboard emulation. */
|
||||
|
||||
#include <devices/common/adb/adbkeyboard.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
EventManager::get_instance()->add_keyboard_handler(this, &AdbKeyboard::event_handler);
|
||||
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
this->pending_events.push_back(std::make_unique<KeyboardEvent>(event));
|
||||
}
|
||||
|
||||
void AdbKeyboard::reset() {
|
||||
this->my_addr = ADB_ADDR_KBD;
|
||||
this->dev_handler_id = 2; // Extended ADB keyboard
|
||||
this->exc_event_flag = 1;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->pending_events.clear();
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_0() {
|
||||
if (this->pending_events.empty()) {
|
||||
return false;
|
||||
}
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = this->consume_pending_event();
|
||||
out_buf[1] = this->consume_pending_event();
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t AdbKeyboard::consume_pending_event() {
|
||||
if (this->pending_events.empty()) {
|
||||
// In most cases we have only one pending event when the host polls us,
|
||||
// but we need to fill two entries of the output buffer. We need to set
|
||||
// the key status bit to 1 (released), and the key to a non-existent
|
||||
// one (0x7F). Otherwise if we leave it empty, the host will think that
|
||||
// the 'a' key (code 0) is pressed (status 0).
|
||||
return 0xFF;
|
||||
}
|
||||
std::unique_ptr<KeyboardEvent> event = std::move(this->pending_events.front());
|
||||
this->pending_events.pop_front();
|
||||
|
||||
uint8_t key_state = 0;
|
||||
if (event->flags & KEYBOARD_EVENT_DOWN) {
|
||||
key_state = 0;
|
||||
} else if (event->flags & KEYBOARD_EVENT_UP) {
|
||||
key_state = 1;
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unknown keyboard event flags %x", this->name.c_str(), event->flags);
|
||||
}
|
||||
|
||||
return (key_state << 7) | (event->key & 0x7F);
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_2() {
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 3: // extended keyboard protocol isn't supported yet
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbKeyboard_Descriptor = {
|
||||
AdbKeyboard::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
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 Apple Desktop Bus Keyboard definitions. */
|
||||
|
||||
#ifndef ADB_KEYBOARD_H
|
||||
#define ADB_KEYBOARD_H
|
||||
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class KeyboardEvent;
|
||||
|
||||
class AdbKeyboard : public AdbDevice {
|
||||
public:
|
||||
AdbKeyboard(std::string name);
|
||||
~AdbKeyboard() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AdbKeyboard>(new AdbKeyboard("ADB-KEYBOARD"));
|
||||
}
|
||||
|
||||
void reset() override;
|
||||
void event_handler(const KeyboardEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
void set_register_2() override;
|
||||
void set_register_3() override;
|
||||
|
||||
|
||||
private:
|
||||
std::deque<std::unique_ptr<KeyboardEvent>> pending_events;
|
||||
|
||||
uint8_t consume_pending_event();
|
||||
};
|
||||
|
||||
// ADB Extended Keyboard raw key codes (most of which eventually became virtual
|
||||
// key codes, see HIToolbox/Events.h).
|
||||
enum AdbKey {
|
||||
AdbKey_A = 0x00,
|
||||
AdbKey_B = 0x0b,
|
||||
AdbKey_C = 0x08,
|
||||
AdbKey_D = 0x02,
|
||||
AdbKey_E = 0x0e,
|
||||
AdbKey_F = 0x03,
|
||||
AdbKey_G = 0x05,
|
||||
AdbKey_H = 0x04,
|
||||
AdbKey_I = 0x22,
|
||||
AdbKey_J = 0x26,
|
||||
AdbKey_K = 0x28,
|
||||
AdbKey_L = 0x25,
|
||||
AdbKey_M = 0x2e,
|
||||
AdbKey_N = 0x2d,
|
||||
AdbKey_O = 0x1f,
|
||||
AdbKey_P = 0x23,
|
||||
AdbKey_Q = 0x0c,
|
||||
AdbKey_R = 0x0f,
|
||||
AdbKey_S = 0x01,
|
||||
AdbKey_T = 0x11,
|
||||
AdbKey_U = 0x20,
|
||||
AdbKey_V = 0x09,
|
||||
AdbKey_W = 0x0d,
|
||||
AdbKey_X = 0x07,
|
||||
AdbKey_Y = 0x10,
|
||||
AdbKey_Z = 0x06,
|
||||
|
||||
AdbKey_1 = 0x12,
|
||||
AdbKey_2 = 0x13,
|
||||
AdbKey_3 = 0x14,
|
||||
AdbKey_4 = 0x15,
|
||||
AdbKey_5 = 0x17,
|
||||
AdbKey_6 = 0x16,
|
||||
AdbKey_7 = 0x1a,
|
||||
AdbKey_8 = 0x1c,
|
||||
AdbKey_9 = 0x19,
|
||||
AdbKey_0 = 0x1d,
|
||||
|
||||
AdbKey_Minus = 0x1b,
|
||||
AdbKey_Equal = 0x18,
|
||||
AdbKey_LeftBracket = 0x21,
|
||||
AdbKey_RightBracket = 0x1e,
|
||||
AdbKey_Backslash = 0x2a,
|
||||
AdbKey_Semicolon = 0x29,
|
||||
AdbKey_Quote = 0x27,
|
||||
AdbKey_Comma = 0x2b,
|
||||
AdbKey_Period = 0x2f,
|
||||
AdbKey_Slash = 0x2c,
|
||||
|
||||
AdbKey_Tab = 0x30,
|
||||
AdbKey_Return = 0x24,
|
||||
AdbKey_Space = 0x31,
|
||||
AdbKey_Delete = 0x33,
|
||||
|
||||
AdbKey_ForwardDelete = 0x75,
|
||||
AdbKey_Help = 0x72,
|
||||
AdbKey_Home = 0x73,
|
||||
AdbKey_End = 0x77,
|
||||
AdbKey_PageUp = 0x74,
|
||||
AdbKey_PageDown = 0x79,
|
||||
|
||||
AdbKey_Grave = 0x32,
|
||||
AdbKey_Escape = 0x35,
|
||||
AdbKey_Control = 0x36,
|
||||
AdbKey_Shift = 0x38,
|
||||
AdbKey_Option = 0x3a,
|
||||
AdbKey_Command = 0x37,
|
||||
AdbKey_CapsLock = 0x39,
|
||||
|
||||
AdbKey_ArrowUp = 0x3e,
|
||||
AdbKey_ArrowDown = 0x3d,
|
||||
AdbKey_ArrowLeft = 0x3b,
|
||||
AdbKey_ArrowRight = 0x3c,
|
||||
|
||||
AdbKey_Keypad0 = 0x52,
|
||||
AdbKey_Keypad1 = 0x53,
|
||||
AdbKey_Keypad2 = 0x54,
|
||||
AdbKey_Keypad3 = 0x55,
|
||||
AdbKey_Keypad4 = 0x56,
|
||||
AdbKey_Keypad5 = 0x57,
|
||||
AdbKey_Keypad6 = 0x58,
|
||||
AdbKey_Keypad7 = 0x59,
|
||||
AdbKey_Keypad9 = 0x5c,
|
||||
AdbKey_Keypad8 = 0x5b,
|
||||
AdbKey_KeypadDecimal = 0x41,
|
||||
AdbKey_KeypadPlus = 0x45,
|
||||
AdbKey_KeypadMinus = 0x4e,
|
||||
AdbKey_KeypadMultiply = 0x43,
|
||||
AdbKey_KeypadDivide = 0x4b,
|
||||
AdbKey_KeypadEnter = 0x4c,
|
||||
AdbKey_KeypadEquals = 0x51,
|
||||
AdbKey_KeypadClear = 0x47,
|
||||
|
||||
AdbKey_F1 = 0x7a,
|
||||
AdbKey_F2 = 0x78,
|
||||
AdbKey_F3 = 0x63,
|
||||
AdbKey_F4 = 0x76,
|
||||
AdbKey_F5 = 0x60,
|
||||
AdbKey_F6 = 0x61,
|
||||
AdbKey_F7 = 0x62,
|
||||
AdbKey_F8 = 0x64,
|
||||
AdbKey_F9 = 0x65,
|
||||
AdbKey_F10 = 0x6d,
|
||||
AdbKey_F11 = 0x67,
|
||||
AdbKey_F12 = 0x6f,
|
||||
AdbKey_F13 = 0x69,
|
||||
AdbKey_F14 = 0x6b,
|
||||
AdbKey_F15 = 0x71,
|
||||
|
||||
AdbKey_ISO1= 0x0A,
|
||||
|
||||
AdbKey_JIS_Yen = 0x5D,
|
||||
AdbKey_JIS_Underscore = 0x5E,
|
||||
AdbKey_JIS_KP_Comma = 0x5F,
|
||||
AdbKey_JIS_Eisu = 0x66,
|
||||
AdbKey_JIS_Kana = 0x68,
|
||||
};
|
||||
|
||||
#endif // ADB_KEYBOARD_H
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
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 Apple Desktop Bus Mouse emulation. */
|
||||
|
||||
#include <devices/common/adb/adbmouse.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <memaccess.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbMouse::AdbMouse(
|
||||
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution
|
||||
) : AdbDevice(name), device_class(device_class), num_buttons(num_buttons), num_bits(num_bits), resolution(resolution)
|
||||
{
|
||||
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
|
||||
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void AdbMouse::event_handler(const MouseEvent& event) {
|
||||
if (event.flags & MOUSE_EVENT_MOTION) {
|
||||
this->x_rel += event.xrel;
|
||||
this->y_rel += event.yrel;
|
||||
this->x_abs = event.xabs;
|
||||
this->y_abs = event.yabs;
|
||||
if (this->device_class == TABLET)
|
||||
this->changed = true;
|
||||
} else if (event.flags & MOUSE_EVENT_BUTTON) {
|
||||
this->buttons_state = event.buttons_state & ((1 << this->num_buttons) - 1);
|
||||
this->x_abs = event.xabs;
|
||||
this->y_abs = event.yabs;
|
||||
this->changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AdbMouse::reset() {
|
||||
this->my_addr = ADB_ADDR_RELPOS;
|
||||
this->dev_handler_id = 1;
|
||||
this->exc_event_flag = 1;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->x_abs = 0;
|
||||
this->y_abs = 0;
|
||||
this->buttons_state = 0;
|
||||
this->changed = false;
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_0(uint8_t buttons_state, bool force) {
|
||||
bool should_update = this->x_rel || this->y_rel || this->changed || force;
|
||||
|
||||
if (should_update) {
|
||||
uint8_t* p;
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
|
||||
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
|
||||
int num_bits, total_bits;
|
||||
// if the mouse is in standard protocol then only send first 2 bytes
|
||||
// BUGBUG: what should tablet do here?
|
||||
if (this->device_class == MOUSE && this->dev_handler_id == 1) {
|
||||
num_bits = total_bits = 7;
|
||||
} else {
|
||||
num_bits = this->num_bits;
|
||||
total_bits = std::max(buttons_to_bits[this->num_buttons], bits_to_bits[num_bits]);
|
||||
}
|
||||
uint8_t buttons_state = ~this->buttons_state;
|
||||
|
||||
for (int axis = 0; axis < 2; axis++) {
|
||||
int bits = num_bits;
|
||||
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
|
||||
: this->device_class == TABLET ? this->y_abs : this->y_rel;
|
||||
if (val < (-1 << (bits - 1)))
|
||||
val = -1 << (bits - 1);
|
||||
else if (val >= (1 << (bits - 1)))
|
||||
val = (1 << (bits - 1)) - 1;
|
||||
int bits_remaining = total_bits;
|
||||
p = &out_buf[axis];
|
||||
int button = axis;
|
||||
bits = 7;
|
||||
|
||||
while (bits_remaining > 0) {
|
||||
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
|
||||
val >>= bits;
|
||||
bits_remaining -= bits;
|
||||
p = bits == 7 ? &out_buf[2] : p + 1;
|
||||
button += 2;
|
||||
bits = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// reset accumulated motion data and button change flag
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->changed = false;
|
||||
|
||||
uint8_t count = (uint8_t)(p - out_buf);
|
||||
this->host_obj->set_output_count(count);
|
||||
return should_update;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_0() {
|
||||
return get_register_0(this->buttons_state, false);
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_1() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
// Identifier
|
||||
out_buf[0] = 'a';
|
||||
out_buf[1] = 'p';
|
||||
out_buf[2] = 'p';
|
||||
out_buf[3] = 'l';
|
||||
// Slightly higher resolution of 300 units per inch
|
||||
WRITE_WORD_BE_A(&out_buf[4], resolution);
|
||||
out_buf[6] = device_class;
|
||||
out_buf[7] = num_buttons;
|
||||
this->host_obj->set_output_count(8);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdbMouse::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 4: // switch over to extended mouse protocol
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AdbMouse::get_buttons_state() const {
|
||||
return this->buttons_state;
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbMouse_Descriptor = {
|
||||
AdbMouse::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 Apple Desktop Bus Mouse definitions. */
|
||||
|
||||
#ifndef ADB_MOUSE_H
|
||||
#define ADB_MOUSE_H
|
||||
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
//#define ABSOLUTE
|
||||
|
||||
class MouseEvent;
|
||||
|
||||
class AdbMouse : public AdbDevice {
|
||||
public:
|
||||
enum DeviceClass {
|
||||
TABLET = 0,
|
||||
MOUSE = 1,
|
||||
TRACKBALL = 2,
|
||||
};
|
||||
|
||||
AdbMouse(
|
||||
std::string name, uint8_t device_class, int num_buttons, int num_bits, uint16_t resolution);
|
||||
~AdbMouse() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
#ifdef ABSOLUTE
|
||||
uint8_t device_class = TABLET;
|
||||
int num_buttons = 3;
|
||||
int num_bits = 16;
|
||||
uint16_t resolution = 72;
|
||||
#else
|
||||
uint8_t device_class = MOUSE;
|
||||
int num_buttons = 3;
|
||||
int num_bits = 10;
|
||||
uint16_t resolution = 300;
|
||||
#endif
|
||||
return std::unique_ptr<AdbMouse>(
|
||||
new AdbMouse("ADB-MOUSE", device_class, num_buttons, num_bits, resolution));
|
||||
}
|
||||
|
||||
void reset() override;
|
||||
void event_handler(const MouseEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
bool get_register_1() override;
|
||||
void set_register_3() override;
|
||||
|
||||
protected:
|
||||
bool get_register_0(uint8_t buttons_state, bool force);
|
||||
uint8_t get_buttons_state() const;
|
||||
|
||||
private:
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
int32_t x_abs = 0;
|
||||
int32_t y_abs = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
uint8_t device_class;
|
||||
int num_buttons;
|
||||
int num_bits;
|
||||
uint16_t resolution;
|
||||
};
|
||||
|
||||
#endif // ADB_MOUSE_H
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
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 Basic ATA device emulation. */
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaBaseDevice::AtaBaseDevice(const std::string name, uint8_t type) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IDE_DEV);
|
||||
|
||||
this->device_type = type;
|
||||
|
||||
device_reset(false);
|
||||
device_set_signature();
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_reset(bool is_soft_reset) {
|
||||
LOG_F(INFO, "%s: %s-reset triggered", this->name.c_str(),
|
||||
is_soft_reset ? "soft" : "hard");
|
||||
|
||||
// Diagnostic code
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
|
||||
// disable interrupts
|
||||
this->r_dev_ctrl |= ATA_CTRL::IEN;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_set_signature() {
|
||||
this->r_sect_count = 1;
|
||||
this->r_sect_num = 1;
|
||||
this->r_dev_head = 0;
|
||||
|
||||
// set ATA protocol signature
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_status = DRDY | DSC; // DSC=1 is required for ATA devices
|
||||
}
|
||||
|
||||
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (this->has_data()) {
|
||||
uint16_t ret_data = this->get_data();
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
} else {
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
this->update_intrq(1);
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
} else {
|
||||
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:
|
||||
this->update_intrq(0);
|
||||
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:
|
||||
if (is_selected() && this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->post_xfer_action();
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0) { // transfer complete?
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
}
|
||||
}
|
||||
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:
|
||||
this->device_control(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
|
||||
// perform ATA Soft Reset if requested
|
||||
if ((this->r_dev_ctrl ^ new_ctrl) & SRST) {
|
||||
if (new_ctrl & SRST) { // SRST set -> phase 0 aka self-test
|
||||
this->r_status |= BSY;
|
||||
this->device_reset(true);
|
||||
} else { // SRST cleared -> phase 1 aka signature and error report
|
||||
if (!this->my_dev_id && this->host_obj->is_device1_present())
|
||||
this->r_error |= 0x80;
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
|
||||
if (this->my_dev_id && this->r_error == 1) {
|
||||
this->host_obj->assert_pdiag();
|
||||
}
|
||||
}
|
||||
}
|
||||
this->r_dev_ctrl = new_ctrl;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
|
||||
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
|
||||
return;
|
||||
|
||||
this->intrq_state = new_intrq_state;
|
||||
this->host_obj->report_intrq(new_intrq_state);
|
||||
}
|
||||
|
||||
void AtaBaseDevice::prepare_xfer(int xfer_size, int block_size) {
|
||||
this->chunk_cnt = std::min(xfer_size, block_size);
|
||||
this->xfer_cnt = xfer_size;
|
||||
this->chunk_size = block_size;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::signal_data_ready() {
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
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 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 "endianswap.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
class IdeChannel;
|
||||
|
||||
class AtaBaseDevice : public HWComponent, public AtaInterface
|
||||
{
|
||||
public:
|
||||
AtaBaseDevice(const std::string name, uint8_t type);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
void set_host(IdeChannel* host, uint8_t dev_id) {
|
||||
this->host_obj = host;
|
||||
this->my_dev_id = dev_id;
|
||||
};
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
int get_device_id() override { return this->my_dev_id; }
|
||||
|
||||
void pdiag_callback() override {
|
||||
this->r_error &= 0x7F;
|
||||
};
|
||||
|
||||
virtual void device_reset(bool is_soft_reset);
|
||||
virtual void device_set_signature();
|
||||
void device_control(const uint8_t new_ctrl);
|
||||
void update_intrq(uint8_t new_intrq_state);
|
||||
void signal_data_ready();
|
||||
|
||||
bool has_data() const {
|
||||
return data_ptr && xfer_cnt;
|
||||
}
|
||||
|
||||
uint16_t get_data() {
|
||||
return BYTESWAP_16(*this->data_ptr++);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool is_selected() const {
|
||||
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
|
||||
}
|
||||
|
||||
void prepare_xfer(int xfer_size, int block_size);
|
||||
|
||||
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
|
||||
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
|
||||
uint8_t intrq_state = 0; // INTRQ deasserted
|
||||
|
||||
IdeChannel* host_obj = nullptr;
|
||||
|
||||
// IDE aka task file registers
|
||||
uint8_t r_error = 0;
|
||||
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_status_save;
|
||||
uint8_t r_dev_ctrl = 0x08 | ata_interface::ATA_CTRL::IEN; // disable interrupts
|
||||
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint16_t *cur_data_ptr = nullptr;
|
||||
alignas(uint16_t)
|
||||
uint8_t data_buf[512] = {};
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
int chunk_size = 0;
|
||||
|
||||
std::function<void()> post_xfer_action = nullptr;
|
||||
};
|
||||
|
||||
#endif // ATA_BASE_DEVICE_H
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
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 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 = 0x00, // 16-bit data (read & write)
|
||||
ERROR = 0x01, // error (read)
|
||||
FEATURES = 0x01, // features (write)
|
||||
SEC_COUNT = 0x02, // sector count
|
||||
SEC_NUM = 0x03, // sector number
|
||||
CYL_LOW = 0x04, // cylinder low
|
||||
CYL_HIGH = 0x05, // cylinder high
|
||||
DEVICE_HEAD = 0x06, // device/head
|
||||
STATUS = 0x07, // status (read)
|
||||
COMMAND = 0x07, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
};
|
||||
|
||||
/** ATAPI specific register offsets. */
|
||||
enum ATAPI_Reg : int {
|
||||
INT_REASON = 0x2, // interrupt reason (read-only)
|
||||
BYTE_COUNT_LO = 0x4, // byte count (bits 0-7)
|
||||
BYTE_COUNT_HI = 0x5, // byte count (bits 8-15)
|
||||
};
|
||||
|
||||
/** ATAPI Interrupt Reason bits. */
|
||||
enum ATAPI_Int_Reason : uint8_t {
|
||||
CoD = 1 << 0,
|
||||
IO = 1 << 1,
|
||||
RELEASE = 1 << 2,
|
||||
};
|
||||
|
||||
/** ATAPI Features bits. */
|
||||
enum ATAPI_Features : uint8_t {
|
||||
DMA = 1 << 0,
|
||||
OVERLAP = 1 << 1
|
||||
};
|
||||
|
||||
/** Device/Head register bits. */
|
||||
enum ATA_Dev_Head : uint8_t {
|
||||
LBA = 1 << 6,
|
||||
};
|
||||
|
||||
/** Status register bits. */
|
||||
enum ATA_Status : uint8_t {
|
||||
ERR = 0x01,
|
||||
IDX = 0x02,
|
||||
CORR = 0x04,
|
||||
DRQ = 0x08,
|
||||
DSC = 0x10,
|
||||
DWF = 0x20,
|
||||
DRDY = 0x40,
|
||||
BSY = 0x80
|
||||
};
|
||||
|
||||
/** Error register bits. */
|
||||
enum ATA_Error : uint8_t {
|
||||
ANMF = 0x01, //no address mark
|
||||
TK0NF = 0x02, //track 0 not found
|
||||
ABRT = 0x04, //abort command
|
||||
MCR = 0x08,
|
||||
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 : uint8_t {
|
||||
IEN = 0x02,
|
||||
SRST = 0x04,
|
||||
HOB = 0x80,
|
||||
};
|
||||
|
||||
/* ATA commands. */
|
||||
enum ATA_Cmd : uint8_t {
|
||||
NOP = 0x00,
|
||||
ATAPI_SOFT_RESET = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
ATAPI_COMMAND_MODE_SENSE6 = 0x1A,
|
||||
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,
|
||||
ATAPI_COMMAND_GET_CONFIG = 0x46,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
ATAPI_PACKET = 0xA0,
|
||||
ATAPI_IDFY_DEV = 0xA1,
|
||||
ATAPI_SERVICE = 0xA2,
|
||||
ATAPI_READ_DVD_STRUCTURE = 0xAD,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
SET_MULTIPLE_MODE = 0xC6,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
STANDBY_IMMEDIATE_E0 = 0xE0,
|
||||
FLUSH_CACHE = 0xE7, // ATA-5
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
SET_FEATURES = 0xEF,
|
||||
};
|
||||
|
||||
}; // namespace ata_interface
|
||||
|
||||
/** 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;
|
||||
virtual void pdiag_callback() {};
|
||||
};
|
||||
|
||||
/** Dummy ATA device. */
|
||||
class AtaNullDevice : public AtaInterface {
|
||||
public:
|
||||
AtaNullDevice() = default;
|
||||
~AtaNullDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override {
|
||||
// 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) override {};
|
||||
|
||||
// invalid device ID means no real device is present
|
||||
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; };
|
||||
};
|
||||
|
||||
#endif // ATA_INTERFACE_H
|
||||
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file ATA hard disk emulation. */
|
||||
|
||||
#include <devices/common/ata/atahd.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <bitset>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaHardDisk::AtaHardDisk(std::string name) : AtaBaseDevice(name, DEVICE_TYPE_ATA) {
|
||||
}
|
||||
|
||||
int AtaHardDisk::device_postinit() {
|
||||
std::string hdd_config = GET_STR_PROP("hdd_config");
|
||||
if (hdd_config.empty()) {
|
||||
LOG_F(ERROR, "%s: hdd_config property is empty", this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string hdd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (hdd_image_path.empty())
|
||||
return 0;
|
||||
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
|
||||
parse_device_path(hdd_config, bus_id, dev_num);
|
||||
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
this->insert_image(hdd_image_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
if (!this->hdd_img.open(filename)) {
|
||||
ABORT_F("%s: could not open image file \"%s\"", this->name.c_str(),
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
this->img_size = this->hdd_img.size();
|
||||
uint64_t sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
|
||||
this->total_sectors = (uint32_t)sectors;
|
||||
if (sectors != this->total_sectors) {
|
||||
ABORT_F("%s: image file \"%s\" is too big", this->name.c_str(),
|
||||
filename.c_str());
|
||||
}
|
||||
this->calc_chs_params();
|
||||
}
|
||||
|
||||
int AtaHardDisk::perform_command() {
|
||||
this->r_status |= BSY;
|
||||
this->r_error = 0;
|
||||
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case ATAPI_SOFT_RESET: // for ATA devices, is a no-op
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case RECALIBRATE: // is optional in ATA-3; disappeared in >= ATA-4
|
||||
// OF 3.1.1 won't boot off the drive that reports error for this command
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_dev_head &= 0xF0;
|
||||
this->r_sect_num = (this->r_dev_head & ATA_Dev_Head::LBA) ? 0 : 1;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_MULTIPLE:
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
int xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == READ_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
hdd_img.read(buffer, offset, xfer_size);
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
// those commands should generate IRQ for each sector
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
break;
|
||||
case WRITE_MULTIPLE:
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == WRITE_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->post_xfer_action = [this]() {
|
||||
uint64_t write_len = (this->cur_data_ptr - this->data_ptr) * sizeof(this->data_ptr[0]);
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, write_len);
|
||||
this->cur_fpos += write_len;
|
||||
};
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
}
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_VERIFY: // verify sectors are readable, just no-op
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
// update fictive disk geometry with parameters from host
|
||||
this->sectors = this->r_sect_count;
|
||||
this->heads = (this->r_dev_head & 0xF) + 1;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case SET_MULTIPLE_MODE: // this command is mandatory for ATA devices
|
||||
if (!this->r_sect_count || this->r_sect_count > SECTORS_PER_INT ||
|
||||
std::bitset<8>(this->r_sect_count).count() != 1) { // power of two?
|
||||
LOG_F(ERROR, "%s: invalid parameter %d for SET_MULTIPLE_MODE",
|
||||
this->name.c_str(), this->r_sect_count);
|
||||
this->r_error |= ABRT;
|
||||
this->r_status |= ERR;
|
||||
} else {
|
||||
LOG_F(9, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(),
|
||||
this->r_sect_count);
|
||||
this->sectors_per_int = this->r_sect_count;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case FLUSH_CACHE: // used by the XNU kernel driver
|
||||
this->r_status &= ~(BSY | DRQ | ERR);
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case IDENTIFY_DEVICE:
|
||||
this->prepare_identify_info();
|
||||
this->data_ptr = (uint16_t *)this->data_buf;
|
||||
this->prepare_xfer(ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
|
||||
this->signal_data_ready();
|
||||
break;
|
||||
case SET_FEATURES:
|
||||
if (this->r_features == 3) {
|
||||
switch(this->r_sect_count >> 3) {
|
||||
case 0:
|
||||
LOG_F(INFO, "%s: default transfer mode requested", this->name.c_str());
|
||||
break;
|
||||
case 1:
|
||||
LOG_F(INFO, "%s: PIO transfer mode set to 0x%X", this->name.c_str(),
|
||||
this->r_sect_count & 7);
|
||||
break;
|
||||
case 4:
|
||||
LOG_F(INFO, "%s: Multiword DMA mode set to 0x%X", this->name.c_str(),
|
||||
this->r_sect_count & 7);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported transfer mode 0x%X", this->name.c_str(),
|
||||
this->r_sect_count);
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unsupported SET_FEATURES subcommand code 0x%X",
|
||||
this->name.c_str(), this->r_features);
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case STANDBY_IMMEDIATE_E0:
|
||||
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
|
||||
this->r_status &= ~BSY;
|
||||
this->r_status |= ERR;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtaHardDisk::prepare_identify_info() {
|
||||
uint16_t *buf_ptr = (uint16_t *)this->data_buf;
|
||||
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
buf_ptr[49] = 0x0200; // report LBA support
|
||||
|
||||
// Maximum number of logical sectors per data block that the device supports
|
||||
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
|
||||
|
||||
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
|
||||
// logical sectors that shall be transferred per data block for
|
||||
// READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
if (this->sectors_per_int)
|
||||
buf_ptr[59] = 0x100 | this->sectors_per_int;
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
|
||||
buf_ptr[57] = this->total_sectors & 0xFFFFU;
|
||||
buf_ptr[58] = (this->total_sectors >> 16) & 0xFFFFU;
|
||||
|
||||
// report LBA capacity
|
||||
WRITE_WORD_LE_A(&buf_ptr[60], (this->total_sectors & 0xFFFFU));
|
||||
WRITE_WORD_LE_A(&buf_ptr[61], (this->total_sectors >> 16) & 0xFFFFU);
|
||||
}
|
||||
|
||||
uint64_t AtaHardDisk::get_lba() {
|
||||
if (this->r_dev_head & ATA_Dev_Head::LBA) {
|
||||
return ((this->r_dev_head & 0xF) << 24) | (this->r_cylinder_hi << 16) |
|
||||
(this->r_cylinder_lo << 8) | (this->r_sect_num);
|
||||
} else { // translate old fashioned CHS addressing to LBA
|
||||
uint16_t c = (this->r_cylinder_hi << 8) + this->r_cylinder_lo;
|
||||
uint8_t h = this->r_dev_head & 0xF;
|
||||
uint8_t s = this->r_sect_num;
|
||||
|
||||
if (!s) {
|
||||
LOG_F(ERROR, "%s: zero sector number is not allowed!", this->name.c_str());
|
||||
return -1ULL;
|
||||
} else
|
||||
return (this->heads * c + h) * this->sectors + s - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void AtaHardDisk::calc_chs_params() {
|
||||
unsigned num_blocks, heads, sectors, max_sectors, cylinders, max_cylinders;
|
||||
|
||||
LOG_F(INFO, "%s: total sectors %d", this->name.c_str(), this->total_sectors);
|
||||
|
||||
if (this->total_sectors >= REAL_CHS_LIMIT) {
|
||||
heads = 16;
|
||||
sectors = 255;
|
||||
cylinders = 65535;
|
||||
LOG_F(WARNING, "%s: exceeds max CHS translation",
|
||||
this->name.c_str());
|
||||
goto done;
|
||||
}
|
||||
|
||||
// use PC BIOS limit to keep number of sectors small for smaller disks
|
||||
if (this->total_sectors >= ATA_BIOS_LIMIT) {
|
||||
max_sectors = 255;
|
||||
max_cylinders = 65535;
|
||||
} else {
|
||||
max_sectors = 63;
|
||||
max_cylinders = 16383;
|
||||
}
|
||||
|
||||
num_blocks = this->total_sectors;
|
||||
|
||||
for (heads = 16; heads > 0; heads--)
|
||||
for (sectors = max_sectors; sectors > 0; sectors--)
|
||||
if (!(num_blocks % (heads * sectors)))
|
||||
if (heads * sectors * max_cylinders >= num_blocks) {
|
||||
cylinders = num_blocks / (heads * sectors);
|
||||
goto done;
|
||||
}
|
||||
|
||||
heads = 16;
|
||||
sectors = (num_blocks + heads * max_cylinders - 1) / (heads * max_cylinders);
|
||||
cylinders = (num_blocks + heads * sectors - 1) / (heads * sectors);
|
||||
|
||||
LOG_F(WARNING, "%s: could not find a suitable CHS translation; increased sectors to %d",
|
||||
this->name.c_str(), heads * sectors * cylinders);
|
||||
|
||||
done:
|
||||
this->heads = heads;
|
||||
this->sectors = sectors;
|
||||
this->cylinders = cylinders;
|
||||
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), cylinders,
|
||||
heads, sectors);
|
||||
}
|
||||
|
||||
static const PropMap AtaHardDisk_Properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtaHardDisk_Descriptor = {
|
||||
AtaHardDisk::create, {}, AtaHardDisk_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file ATA hard disk definitions. */
|
||||
|
||||
#ifndef ATA_HARD_DISK_H
|
||||
#define ATA_HARD_DISK_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <utils/imgfile.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
constexpr auto ATA_HD_SEC_SIZE = 512;
|
||||
constexpr auto SECTORS_PER_INT = 16;
|
||||
|
||||
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
|
||||
constexpr auto ATA_BIOS_LIMIT = 16514064;
|
||||
// C:65535 x H:16 x S:255 = 127.498 GiB = 136.900 GB = largest identify
|
||||
constexpr auto REAL_CHS_LIMIT = 267382800;
|
||||
// C:65536 x H:16 x S:255 = 127.500 GiB = 136.902 GB = largest address
|
||||
constexpr auto CHS_LIMIT = 267386880;
|
||||
|
||||
class AtaHardDisk : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
AtaHardDisk(std::string name);
|
||||
~AtaHardDisk() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AtaHardDisk>(new AtaHardDisk("ATA-HD"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void insert_image(std::string filename);
|
||||
int perform_command() override;
|
||||
|
||||
protected:
|
||||
void prepare_identify_info();
|
||||
uint64_t get_lba();
|
||||
void calc_chs_params();
|
||||
|
||||
private:
|
||||
ImgFile hdd_img;
|
||||
uint64_t img_size = 0;
|
||||
uint32_t total_sectors = 0;
|
||||
uint64_t cur_fpos = 0;
|
||||
|
||||
// fictive disk geometry for CHS-to-LBA translation
|
||||
uint16_t cylinders;
|
||||
uint8_t heads;
|
||||
uint8_t sectors;
|
||||
|
||||
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
|
||||
|
||||
char * buffer = new char[1 <<17];
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
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 Basic ATAPI interface emulation. */
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atapibasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtapiBaseDevice::AtapiBaseDevice(const std::string name)
|
||||
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI) {
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::device_set_signature() {
|
||||
this->r_int_reason = 1; // shadows ATA r_sect_count
|
||||
this->r_sect_num = 1; // required for protocol identification in OF 2.x
|
||||
this->r_dev_head = 0;
|
||||
|
||||
// set ATAPI protocol signature
|
||||
this->r_byte_count = 0xEB14;
|
||||
this->r_status_save = this->r_status; // for restoring on the first command
|
||||
this->r_status = 0;
|
||||
}
|
||||
|
||||
uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (has_data()) {
|
||||
uint16_t ret_data = get_data();
|
||||
this->xfer_cnt -= 2;
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->r_status &= ~DRQ;
|
||||
|
||||
if ((this->r_int_reason & ATAPI_Int_Reason::IO) &&
|
||||
!(this->r_int_reason & ATAPI_Int_Reason::CoD)
|
||||
) {
|
||||
if (this->data_available()) {
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status |= BSY;
|
||||
this->update_intrq(1); // Is this going to work here? The interrupt happens before returning ret_data.
|
||||
}
|
||||
else if (this->status_expected) {
|
||||
this->present_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
} else {
|
||||
return 0xFFFFU;
|
||||
}
|
||||
case ATA_Reg::ERROR:
|
||||
return this->r_error;
|
||||
case ATAPI_Reg::INT_REASON:
|
||||
return this->r_int_reason;
|
||||
case ATA_Reg::SEC_NUM:
|
||||
return this->r_sect_num;
|
||||
case ATAPI_Reg::BYTE_COUNT_LO:
|
||||
return this->r_byte_count & 0xFFU;
|
||||
case ATAPI_Reg::BYTE_COUNT_HI:
|
||||
return (this->r_byte_count >> 8) & 0xFFU;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
return this->r_dev_head;
|
||||
case ATA_Reg::STATUS:
|
||||
this->update_intrq(0);
|
||||
return this->r_status;
|
||||
case ATA_Reg::ALT_STATUS:
|
||||
if (this->r_status & BSY && this->data_available()) {
|
||||
this->r_byte_count = this->request_data();
|
||||
this->data_out_phase();
|
||||
}
|
||||
return this->r_status;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to read unknown register: %x", reg_addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (has_data()) {
|
||||
*this->data_ptr++ = BYTESWAP_16(value);
|
||||
this->xfer_cnt -= 2;
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->r_status &= ~DRQ;
|
||||
if (this->r_int_reason & CoD) {
|
||||
this->perform_packet_command();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATA_Reg::FEATURES:
|
||||
this->r_features = value;
|
||||
break;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
case ATA_Reg::SEC_NUM:
|
||||
break; // unused in ATAPI, NoOp them here for compatibility
|
||||
case ATAPI_Reg::BYTE_COUNT_LO:
|
||||
this->r_byte_count = (this->r_byte_count & 0xFF00U) | (value & 0xFFU);
|
||||
break;
|
||||
case ATAPI_Reg::BYTE_COUNT_HI:
|
||||
this->r_byte_count = (this->r_byte_count & 0xFFU) | ((value & 0xFFU) << 8);
|
||||
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:
|
||||
this->device_control(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
int AtapiBaseDevice::perform_command() {
|
||||
this->r_error &= ~ATA_Error::ABRT;
|
||||
this->r_status &= ~ATA_Status::ERR;
|
||||
this->r_status |= BSY;
|
||||
|
||||
switch (this->r_command) {
|
||||
case ATAPI_SOFT_RESET:
|
||||
this->device_reset(true);
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case ATAPI_PACKET:
|
||||
this->data_ptr = (uint16_t *)this->cmd_pkt;
|
||||
this->xfer_cnt = sizeof(this->cmd_pkt);
|
||||
this->r_int_reason &= ~ATAPI_Int_Reason::IO; // host->device
|
||||
this->r_int_reason |= ATAPI_Int_Reason::CoD; // command packet
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case ATAPI_IDFY_DEV:
|
||||
std::memset(this->data_buf, 0, 512);
|
||||
this->data_buf[0] = 0xC0;
|
||||
this->data_buf[1] = 0x85;
|
||||
this->data_ptr = (uint16_t *)this->data_buf;
|
||||
this->xfer_cnt = 512;
|
||||
this->status_expected = false;
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case SET_FEATURES:
|
||||
switch (this->r_features) {
|
||||
case 3: // set transfer mode
|
||||
LOG_F(INFO, "%s: xfer_type=0x%X, mode=0x%X", this->name.c_str(),
|
||||
this->r_sect_count >> 3, this->r_sect_count & 7);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported subcommand 0x%X in SET_FEATURES",
|
||||
this->name.c_str(), this->r_features);
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), this->r_command);
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::data_out_phase() {
|
||||
this->r_int_reason |= ATAPI_Int_Reason::IO; // device->host
|
||||
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
|
||||
this->signal_data_ready();
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::present_status() {
|
||||
this->r_int_reason |= ATAPI_Int_Reason::IO;
|
||||
this->r_int_reason |= ATAPI_Int_Reason::CoD;
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
/** @file Base class for ATAPI devices. */
|
||||
|
||||
#ifndef ATAPI_BASE_DEVICE_H
|
||||
#define ATAPI_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
class AtapiBaseDevice : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
AtapiBaseDevice(const std::string name);
|
||||
~AtapiBaseDevice() = default;
|
||||
|
||||
void device_set_signature() override;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
|
||||
// methods to be implemented in the particular device
|
||||
int perform_command() override;
|
||||
virtual void perform_packet_command() = 0;
|
||||
virtual int request_data() = 0;
|
||||
virtual bool data_available() = 0;
|
||||
|
||||
// methods with default implementation
|
||||
virtual void data_out_phase();
|
||||
virtual void present_status();
|
||||
|
||||
protected:
|
||||
uint8_t r_int_reason;
|
||||
uint16_t r_byte_count;
|
||||
bool status_expected = false;
|
||||
|
||||
alignas(uint16_t)
|
||||
uint8_t cmd_pkt[12] = {};
|
||||
};
|
||||
|
||||
#endif // ATAPI_BASE_DEVICE_H
|
||||
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
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 ATAPI CDROM implementation. */
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/atapicdrom.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/scsi/scsi.h> // ATAPI CDROM reuses SCSI commands (sic!)
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtapiCdrom::AtapiCdrom(std::string name) : CdromDrive(), AtapiBaseDevice(name) {
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->status_error(sense_key, asc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
int AtapiCdrom::device_postinit() {
|
||||
std::string cdr_config = GET_STR_PROP("cdr_config");
|
||||
if (cdr_config.empty()) {
|
||||
LOG_F(ERROR, "%s: cdr_config property is empty", this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
|
||||
parse_device_path(cdr_config, bus_id, dev_num);
|
||||
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
std::string cdr_image_path = GET_STR_PROP("cdr_img");
|
||||
if (!cdr_image_path.empty()) {
|
||||
this->insert_image(cdr_image_path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtapiCdrom::perform_packet_command() {
|
||||
uint32_t lba, xfer_len;
|
||||
|
||||
this->r_status |= BSY;
|
||||
this->sector_areas = 0;
|
||||
if (this->doing_sector_areas) {
|
||||
this->doing_sector_areas = false;
|
||||
LOG_F(WARNING, "%s: doing_sector_areas reset", this->name.c_str());
|
||||
}
|
||||
|
||||
switch (this->cmd_pkt[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
if (this->medium_present())
|
||||
this->status_good();
|
||||
else
|
||||
this->status_error(ScsiSense::NOT_READY, ScsiError::MEDIUM_NOT_PRESENT);
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
xfer_len = this->request_sense(this->data_buf, this->sense_key, this->asc, this->ascq);
|
||||
if (!xfer_len) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->xfer_cnt = this->inquiry(this->cmd_pkt, this->data_buf);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
if ((this->cmd_pkt[4] & 3) == 2) {
|
||||
LOG_F(WARNING, "CD-ROM eject requested");
|
||||
}
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
LOG_F(INFO, "%s: medium removal %s", this->name.c_str(),
|
||||
this->cmd_pkt[4] & 1 ? "prevented" : "allowed");
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->xfer_cnt = this->report_capacity(this->data_buf);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->status_good();
|
||||
xfer_len = this->read_toc(this->cmd_pkt, this->data_buf);
|
||||
if (!xfer_len) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->xfer_cnt = this->mode_sense_ex(true, this->cmd_pkt, this->data_buf);
|
||||
if (!this->xfer_cnt) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
|
||||
if (!this->xfer_cnt) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = this->cmd_pkt[4];
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
LOG_F(INFO, "%s: speed set to %d kBps", this->name.c_str(),
|
||||
READ_WORD_BE_U(&this->cmd_pkt[2]));
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
{
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
|
||||
if (this->cmd_pkt[1] || (this->cmd_pkt[9] & ~0xf8) || ((this->cmd_pkt[9] & 0xf8) == 0) || this->cmd_pkt[10])
|
||||
LOG_F(WARNING, "%s: unsupported READ_CD params: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
this->name.c_str(),
|
||||
this->cmd_pkt[0], this->cmd_pkt[1], this->cmd_pkt[2], this->cmd_pkt[3], this->cmd_pkt[4], this->cmd_pkt[5],
|
||||
this->cmd_pkt[6], this->cmd_pkt[7], this->cmd_pkt[8], this->cmd_pkt[9], this->cmd_pkt[10], this->cmd_pkt[11]
|
||||
);
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->sector_areas = cmd_pkt[9];
|
||||
this->doing_sector_areas = true;
|
||||
this->current_block = lba;
|
||||
this->current_block_byte = 0;
|
||||
|
||||
int bytes_prolog = 0;
|
||||
int bytes_data = 0;
|
||||
int bytes_epilog = 0;
|
||||
|
||||
// For Mode 1 CD-ROMs:
|
||||
if (this->sector_areas & 0x80) bytes_prolog += 12; // Sync
|
||||
if (this->sector_areas & 0x20) bytes_prolog += 4; // Header
|
||||
if (this->sector_areas & 0x40) bytes_prolog += 0; // SubHeader
|
||||
if (this->sector_areas & 0x10) bytes_data += 2048; // User
|
||||
if (this->sector_areas & 0x08) bytes_epilog += 288; // Auxiliary
|
||||
if (this->sector_areas & 0x02) bytes_epilog += 294; // ErrorFlags
|
||||
if (this->sector_areas & 0x01) bytes_epilog += 96; // SubChannel
|
||||
|
||||
int bytes_per_block = bytes_prolog + bytes_data + bytes_epilog;
|
||||
|
||||
int disk_image_byte_count;
|
||||
|
||||
if (bytes_per_block == 0) {
|
||||
disk_image_byte_count = 0xffff;
|
||||
}
|
||||
else {
|
||||
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
|
||||
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
|
||||
int disk_image_byte_count_partial_block =
|
||||
(this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
|
||||
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
|
||||
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
|
||||
}
|
||||
// add partial block
|
||||
disk_image_byte_count += disk_image_byte_count_partial_block;
|
||||
}
|
||||
}
|
||||
|
||||
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
|
||||
|
||||
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog +
|
||||
(disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
|
||||
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
|
||||
bytes_received = this->r_byte_count; // confine to r_byte_count
|
||||
}
|
||||
this->r_byte_count = bytes_received;
|
||||
this->xfer_cnt = bytes_received;
|
||||
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
|
||||
this->cmd_pkt[0]);
|
||||
this->status_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CMD);
|
||||
this->present_status();
|
||||
}
|
||||
}
|
||||
|
||||
int AtapiCdrom::request_data() {
|
||||
// continuation of READ_CD above
|
||||
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
|
||||
this->xfer_cnt = this->read_more();
|
||||
|
||||
return this->xfer_cnt;
|
||||
}
|
||||
|
||||
static const uint8_t mode_1_sync[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
|
||||
|
||||
uint16_t AtapiCdrom::get_data() {
|
||||
uint16_t ret_data;
|
||||
|
||||
if (doing_sector_areas) {
|
||||
// For Mode 1 CD-ROMs:
|
||||
int area_start;
|
||||
int area_end = 0;
|
||||
|
||||
ret_data = 0xffff;
|
||||
|
||||
if (this->sector_areas & 0x80) {
|
||||
area_start = area_end;
|
||||
area_end += 12; // Sync
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = BYTESWAP_16(*((uint16_t*)(&mode_1_sync[current_block_byte - area_start])));
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x20) {
|
||||
area_start = area_end;
|
||||
area_end += 4; // Header
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
AddrMsf msf = lba_to_msf(this->current_block + 150);
|
||||
uint8_t header[4];
|
||||
header[0] = msf.min;
|
||||
header[1] = msf.sec;
|
||||
header[2] = msf.frm;
|
||||
header[3] = 0x01; // Mode 1
|
||||
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x40) {
|
||||
area_start = area_end;
|
||||
area_end += 0; // SubHeader
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x10) {
|
||||
area_start = area_end;
|
||||
area_end += 2048; // User
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = AtaBaseDevice::get_data();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x08) {
|
||||
area_start = area_end;
|
||||
area_end += 288; // Auxiliary
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x02) {
|
||||
area_start = area_end;
|
||||
area_end += 294; // ErrorFlags
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x01) {
|
||||
area_start = area_end;
|
||||
area_end += 96; // SubChannel
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
current_block_byte += 2;
|
||||
if (current_block_byte >= area_end)
|
||||
current_block_byte = 0;
|
||||
}
|
||||
else {
|
||||
ret_data = AtaBaseDevice::get_data();
|
||||
}
|
||||
|
||||
return ret_data;
|
||||
}
|
||||
|
||||
void AtapiCdrom::status_good() {
|
||||
this->status_expected = true;
|
||||
this->r_error = 0;
|
||||
this->sense_key = 0;
|
||||
this->r_status &= ~ATA_Status::ERR;
|
||||
}
|
||||
|
||||
void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
|
||||
this->status_expected = true;
|
||||
this->sense_key = sense_key;
|
||||
this->asc = asc;
|
||||
this->r_error = (sense_key << 4) | ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
|
||||
static const PropMap AtapiCdrom_Properties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtapiCdrom_Descriptor = {
|
||||
AtapiCdrom::create, {}, AtapiCdrom_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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 ATAPI CDROM definitions. */
|
||||
|
||||
#ifndef ATAPI_CDROM_H
|
||||
#define ATAPI_CDROM_H
|
||||
|
||||
#include <devices/common/ata/atapibasedevice.h>
|
||||
#include <devices/storage/cdromdrive.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class AtapiCdrom : public CdromDrive, public AtapiBaseDevice {
|
||||
public:
|
||||
AtapiCdrom(std::string name);
|
||||
~AtapiCdrom() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AtapiCdrom>(new AtapiCdrom("ATAPI-CDROM"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void perform_packet_command() override;
|
||||
|
||||
int request_data() override;
|
||||
|
||||
bool data_available() override {
|
||||
return this->data_left() != 0;
|
||||
}
|
||||
|
||||
void status_good();
|
||||
void status_error(uint8_t sense_key, uint8_t asc);
|
||||
|
||||
uint16_t get_data();
|
||||
private:
|
||||
uint8_t sense_key = 0;
|
||||
uint8_t asc = 0;
|
||||
uint8_t ascq = 0;
|
||||
|
||||
bool doing_sector_areas = false;
|
||||
uint8_t sector_areas;
|
||||
uint32_t current_block;
|
||||
uint16_t current_block_byte;
|
||||
};
|
||||
|
||||
#endif // ATAPI_CDROM_H
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file CMD646U2 PCI Ultra ATA controller emulation. */
|
||||
|
||||
#include <devices/common/ata/cmd646.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
CmdIdeCtrl::CmdIdeCtrl() : PCIDevice("cmd-ide") {
|
||||
this->supports_types(HWCompType::PCI_DEV | HWCompType::IDE_HOST);
|
||||
|
||||
// set up PCI configuration space header
|
||||
this->vendor_id = this->subsys_vndr = PCI_VENDOR_SILICON_IMAGE;
|
||||
this->device_id = this->subsys_id = DEV_ID_CMD646;
|
||||
this->class_rev = ((MY_DEV_CLASS | this->prog_if) << 8) | MY_REV_ID;
|
||||
this->max_lat = 4;
|
||||
this->min_gnt = 2;
|
||||
this->irq_pin = 1;
|
||||
|
||||
this->bars_cfg[0] = 0xFFFFFFF9; // Command block I/O space, primary channel
|
||||
this->bars_cfg[1] = 0xFFFFFFFD; // Control block I/O space, primary channel
|
||||
this->bars_cfg[2] = 0xFFFFFFF9; // Command block I/O space, secondary channel
|
||||
this->bars_cfg[3] = 0xFFFFFFFD; // Control block I/O space, secondary channel
|
||||
this->bars_cfg[4] = 0xFFFFFFF1; // Bus master I/O space, both channels
|
||||
|
||||
this->finish_config_bars();
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
gMachineObj->add_device("CmdAta0", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta0")));
|
||||
gMachineObj->add_device("CmdAta1", std::unique_ptr<IdeChannel>(new IdeChannel("CmdAta1")));
|
||||
|
||||
this->ch0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta0"));
|
||||
this->ch1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("CmdAta1"));
|
||||
|
||||
this->ch0->set_irq_callback([this](const uint8_t intrq_state) {
|
||||
LOG_F(INFO, "CmdAta0 INTRQ updated to %d", intrq_state);
|
||||
this->update_irq(0, intrq_state);
|
||||
});
|
||||
|
||||
this->ch1->set_irq_callback([this](const uint8_t intrq_state) {
|
||||
LOG_F(INFO, "CmdAta1 INTRQ updated to %d", intrq_state);
|
||||
this->update_irq(1, intrq_state);
|
||||
});
|
||||
}
|
||||
|
||||
uint32_t CmdIdeCtrl::pci_cfg_read(uint32_t reg_offs, AccessDetails &details) {
|
||||
if (reg_offs < 64)
|
||||
return PCIDevice::pci_cfg_read(reg_offs, details);
|
||||
|
||||
if (details.size != 1)
|
||||
ABORT_F("%s: non-byte read from PCI config reg 0x%X", this->name.c_str(),
|
||||
reg_offs + details.offset);
|
||||
|
||||
if (reg_offs < 112)
|
||||
return this->read_config_reg(reg_offs + details.offset);
|
||||
|
||||
LOG_F(WARNING, "%s: reading config reg at 0x%X", this->name.c_str(), reg_offs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CmdIdeCtrl::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;
|
||||
}
|
||||
|
||||
if (details.size != 1)
|
||||
ABORT_F("%s: non-byte write to PCI config reg 0x%X", this->name.c_str(),
|
||||
reg_offs + details.offset);
|
||||
|
||||
if (reg_offs < 112)
|
||||
this->write_config_reg(reg_offs + details.offset, value);
|
||||
else
|
||||
LOG_F(WARNING, "%s: writing config reg at 0x%X", this->name.c_str(), reg_offs);
|
||||
}
|
||||
|
||||
void CmdIdeCtrl::notify_bar_change(int bar_num) {
|
||||
if (bar_num >= 0 && bar_num <= 4)
|
||||
this->io_bases[bar_num] = this->bars[bar_num] & ~3;
|
||||
}
|
||||
|
||||
bool CmdIdeCtrl::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
*res = 0;
|
||||
|
||||
if ((offset & ~7) == this->io_bases[0]) {
|
||||
*res = this->ch0->read(offset & 7, size);
|
||||
} else if ((offset & ~7) == this->io_bases[2]) {
|
||||
*res = this->ch1->read(offset & 7, size);
|
||||
} else if ((offset & ~3) == this->io_bases[1]) {
|
||||
*res = this->ch0->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
|
||||
} else if ((offset & ~3) == this->io_bases[3]) {
|
||||
*res = this->ch1->read((offset & 3) + DEV_CTRL_BLK_OFFSET, size);
|
||||
} else if ((offset & ~0xF) == this->io_bases[4]) {
|
||||
*res = this->read_bus_master_reg(offset & 0xF);
|
||||
} else {
|
||||
*res = 0xFFFFFFFFUL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CmdIdeCtrl::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
if ((offset & ~7) == this->io_bases[0]) {
|
||||
this->ch0->write(offset & 7, value, size);
|
||||
} else if ((offset & ~7) == this->io_bases[2]) {
|
||||
this->ch1->write(offset & 7, value, size);
|
||||
} else if ((offset & ~3) == this->io_bases[1]) {
|
||||
this->ch0->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
|
||||
} else if ((offset & ~3) == this->io_bases[3]) {
|
||||
this->ch1->write((offset & 3) + DEV_CTRL_BLK_OFFSET, value, size);
|
||||
} else if ((offset & ~0xF) == this->io_bases[4]) {
|
||||
this->write_bus_master_reg(offset & 0xF, value & 0xFFU);
|
||||
} else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
uint8_t CmdIdeCtrl::read_config_reg(uint32_t reg_offset) {
|
||||
switch(reg_offset) {
|
||||
case ARTTIM0:
|
||||
return this->addr_setup_time_0;
|
||||
case DRWTIM0:
|
||||
return this->data_rw_time_0;
|
||||
case ARTTIM1:
|
||||
return this->addr_setup_time_1;
|
||||
case DRWTIM1:
|
||||
return this->data_rw_time_1;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
|
||||
reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CmdIdeCtrl::write_config_reg(uint32_t reg_offset, uint8_t val) {
|
||||
switch(reg_offset) {
|
||||
case ARTTIM0:
|
||||
this->addr_setup_time_0 = val;
|
||||
LOG_F(9, "%s: ARTTIM0 set to 0x%X", this->name.c_str(), val);
|
||||
break;
|
||||
case DRWTIM0:
|
||||
this->data_rw_time_0 = val;
|
||||
LOG_F(9, "%s: DRWTIM0 set to 0x%X", this->name.c_str(), val);
|
||||
break;
|
||||
case ARTTIM1:
|
||||
this->addr_setup_time_1 = val;
|
||||
LOG_F(9, "%s: ARTTIM1 set to 0x%X", this->name.c_str(), val);
|
||||
break;
|
||||
case DRWTIM1:
|
||||
this->data_rw_time_1 = val;
|
||||
LOG_F(9, "%s: DRWTIM1 set to 0x%X", this->name.c_str(), val);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unimplemented config reg at 0x%X", this->name.c_str(),
|
||||
reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CmdIdeCtrl::read_bus_master_reg(const uint8_t reg_offset) {
|
||||
switch(reg_offset) {
|
||||
case MRDMODE:
|
||||
return this->mrdmode;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
|
||||
reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CmdIdeCtrl::write_bus_master_reg(const uint8_t reg_offset, const uint8_t val) {
|
||||
switch(reg_offset) {
|
||||
case MRDMODE:
|
||||
if (val & BM_CH0_INT)
|
||||
this->mrdmode &= ~BM_CH0_INT;
|
||||
if (val & BM_CH1_INT)
|
||||
this->mrdmode &= ~BM_CH1_INT;
|
||||
this->mrdmode = (this->mrdmode & ~(BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT)) |
|
||||
(val & (BM_BLOCK_CH0_INT | BM_BLOCK_CH1_INT));
|
||||
LOG_F(INFO, "%s: MRDMODE set to 0x%X", this->name.c_str(), val);
|
||||
if ((this->mrdmode & BM_CH0_INT) && !(this->mrdmode & BM_BLOCK_CH0_INT))
|
||||
this->update_irq(0, 1);
|
||||
if ((this->mrdmode & BM_CH1_INT) && !(this->mrdmode & BM_BLOCK_CH1_INT))
|
||||
this->update_irq(1, 1);
|
||||
break;
|
||||
case UDIDETCR0:
|
||||
this->udma_time_cr = val;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unimplemented bus master reg at 0x%X", this->name.c_str(),
|
||||
reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void CmdIdeCtrl::update_irq(const int ch_num, const uint8_t irq_level) {
|
||||
bool forward_irq = !(this->mrdmode & (ch_num ? BM_BLOCK_CH1_INT : BM_BLOCK_CH0_INT));
|
||||
|
||||
if (irq_level)
|
||||
this->mrdmode |= ch_num ? BM_CH1_INT : BM_CH0_INT;
|
||||
else
|
||||
this->mrdmode &= ~(ch_num ? BM_CH1_INT : BM_CH0_INT);
|
||||
|
||||
if (!irq_level || forward_irq)
|
||||
this->pci_interrupt(irq_level);
|
||||
}
|
||||
|
||||
static const DeviceDescription CmdIde_Descriptor = {
|
||||
CmdIdeCtrl::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(CmdAta, CmdIde_Descriptor);
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file CMD646U2 PCI Ultra ATA controller definitions. */
|
||||
|
||||
#ifndef CMD646_IDE_H
|
||||
#define CMD646_IDE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
constexpr auto DEV_ID_CMD646 = 0x646;
|
||||
constexpr auto MY_DEV_CLASS = 0x010180; // mass storage | IDE controller | IDE master
|
||||
constexpr auto MY_REV_ID = 7;
|
||||
|
||||
// Offset for converting addresses of the device control block registers
|
||||
// defined in the PCI IDE Controller specification, rev. 1.0 3/4/94
|
||||
// to the addresses used in IdeChannel
|
||||
constexpr auto DEV_CTRL_BLK_OFFSET = 0x14;
|
||||
|
||||
/** CMD646 control/status registers. */
|
||||
enum {
|
||||
ARTTIM0 = 0x53,
|
||||
DRWTIM0 = 0x54,
|
||||
ARTTIM1 = 0x55,
|
||||
DRWTIM1 = 0x56,
|
||||
};
|
||||
|
||||
/** CMD646 bus master registers. */
|
||||
enum {
|
||||
MRDMODE = 1, // misnomer, contains interrupt control/status bits (CMD646U2 specific)
|
||||
UDIDETCR0 = 3, // Ultra DMA timing control register (CMD646U2 specific)
|
||||
};
|
||||
|
||||
/** Bit definitions for the MRDMODE register. */
|
||||
enum {
|
||||
BM_CH0_INT = 1 << 2,
|
||||
BM_CH1_INT = 1 << 3,
|
||||
BM_BLOCK_CH0_INT = 1 << 4,
|
||||
BM_BLOCK_CH1_INT = 1 << 5,
|
||||
};
|
||||
|
||||
class CmdIdeCtrl : public PCIDevice {
|
||||
public:
|
||||
CmdIdeCtrl();
|
||||
~CmdIdeCtrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<CmdIdeCtrl>(new CmdIdeCtrl());
|
||||
}
|
||||
|
||||
// PCIDevice methods
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
|
||||
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) override;
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size) override;
|
||||
|
||||
private:
|
||||
void notify_bar_change(int bar_num);
|
||||
uint8_t read_config_reg(uint32_t reg_offset);
|
||||
void write_config_reg(uint32_t reg_offset, uint8_t val);
|
||||
uint8_t read_bus_master_reg(const uint8_t reg_offset);
|
||||
void write_bus_master_reg(const uint8_t reg_offset, const uint8_t val);
|
||||
void update_irq(const int ch_num, const uint8_t irq_level);
|
||||
|
||||
// on reset, programming interface defaults to
|
||||
// "both channels operating in native mode"
|
||||
uint8_t prog_if = 0x0F;
|
||||
|
||||
uint32_t io_bases[5] = {};
|
||||
|
||||
IdeChannel *ch0 = nullptr;
|
||||
IdeChannel *ch1 = nullptr;
|
||||
|
||||
// unknown default, set it to 2 clocks (60 ns)
|
||||
uint8_t addr_setup_time_0 = 0x40; // address setup time for drive 0
|
||||
uint8_t addr_setup_time_1 = 0x40; // address setup time for drive 1
|
||||
uint8_t data_rw_time_0 = 0x00; // data read/write time for drive 0
|
||||
uint8_t data_rw_time_1 = 0x00; // data read/write time for drive 1
|
||||
|
||||
uint8_t mrdmode = 0;
|
||||
uint8_t udma_time_cr = 0;
|
||||
};
|
||||
|
||||
#endif // CMD646_IDE_H
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** IDE Channel (aka IDE port) emulation.
|
||||
|
||||
One IDE channel is capable of controlling up to two IDE devices.
|
||||
|
||||
IdeChannel class handles device registration and passing of messages
|
||||
from and to the host.
|
||||
|
||||
MacioIdeChannel class implements MacIO specific registers
|
||||
and interrupt handling.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#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->device_stub = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
|
||||
this->devices[0] = this->device_stub.get();
|
||||
this->devices[1] = this->device_stub.get();
|
||||
}
|
||||
|
||||
void IdeChannel::register_device(int id, AtaInterface* dev_obj) {
|
||||
if (id < 0 || id >= 2)
|
||||
ABORT_F("%s: invalid device ID", this->name.c_str());
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this, id);
|
||||
}
|
||||
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size) {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
|
||||
void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
int MacioIdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
this->irq_callback = [this](const uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t MacioIdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else
|
||||
return IdeChannel::read(reg_addr, size);
|
||||
}
|
||||
|
||||
void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else
|
||||
IdeChannel::write(reg_addr, val, size);
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
MacioIdeChannel::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
MacioIdeChannel::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
REGISTER_DEVICE(Ide1, Ide1_Descriptor);
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file 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 <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class IdeChannel : public HWComponent
|
||||
{
|
||||
public:
|
||||
IdeChannel(const std::string name);
|
||||
~IdeChannel() = default;
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
}
|
||||
|
||||
bool is_device1_present() {
|
||||
return this->devices[1]->get_device_id() != ata_interface::DEVICE_ID_INVALID;
|
||||
}
|
||||
|
||||
void set_irq_callback(std::function<void(const uint8_t intrq_state)> cb) {
|
||||
this->irq_callback = cb;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->irq_callback(intrq_state);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
AtaInterface* devices[2];
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
};
|
||||
|
||||
/** This class models an IDE channel specific to MacIO ASICs. */
|
||||
class MacioIdeChannel : public IdeChannel
|
||||
{
|
||||
public:
|
||||
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
|
||||
~MacioIdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
private:
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
// interrupt stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @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/clockgen/athens.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr)
|
||||
{
|
||||
set_name("Athens");
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
|
||||
// This initialization is not prescribed
|
||||
// but let's set them to acceptable values anyway
|
||||
this->regs[AthensRegs::D2] = 2;
|
||||
this->regs[AthensRegs::N2] = 2;
|
||||
|
||||
// set P2_MUX2 on power up as follows:
|
||||
// - dot clock VCO is disabled
|
||||
// - dot clock = reference clock / 2
|
||||
this->regs[AthensRegs::P2_MUX2] = 0x62;
|
||||
}
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr, const float crystal_freq)
|
||||
: AthensClocks(dev_addr)
|
||||
{
|
||||
this->xtal_freq = crystal_freq;
|
||||
}
|
||||
|
||||
void AthensClocks::start_transaction()
|
||||
{
|
||||
this->pos = 0; // reset read/write position
|
||||
}
|
||||
|
||||
bool AthensClocks::send_subaddress(uint8_t sub_addr)
|
||||
{
|
||||
LOG_F(INFO, "%s: subaddress set to 0x%X", this->name.c_str(), 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, "%s: invalid register number %d", this->name.c_str(),
|
||||
this->reg_num);
|
||||
return false; // return NACK
|
||||
}
|
||||
this->regs[this->reg_num] = data;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
|
||||
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] & 0x80) {
|
||||
LOG_F(INFO, "%s: dot clock disabled", this->name.c_str());
|
||||
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, "%s: untested D2 value %d", this->name.c_str(), d2);
|
||||
}
|
||||
|
||||
if (std::find(N2_commons.begin(), N2_commons.end(), n2) == N2_commons.end()) {
|
||||
LOG_F(WARNING, "%s: untested N2 value %d", this->name.c_str(), d2);
|
||||
}
|
||||
|
||||
int mux = (this->regs[AthensRegs::P2_MUX2] >> 4) & 3;
|
||||
|
||||
switch (mux) {
|
||||
case 0: // clock source -> dot cock VCO
|
||||
out_freq = this->xtal_freq * ((float)n2 / (float)(d2 * post_div));
|
||||
break;
|
||||
case 1: // clock source -> system clock VCO
|
||||
LOG_F(WARNING, "%s: system clock VCO not supported yet!", this->name.c_str());
|
||||
break;
|
||||
case 2: // clock source -> crystal frequency
|
||||
out_freq = this->xtal_freq / post_div;
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(WARNING, "%s: attempt to use reserved Mux value!", this->name.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s: dot clock frequency set to %f Hz", this->name.c_str(), out_freq);
|
||||
|
||||
return static_cast<int>(out_freq + 0.5f);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Athens clock generator definitions. */
|
||||
|
||||
#ifndef ATHENS_H
|
||||
#define ATHENS_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
constexpr auto ATHENS_NUM_REGS = 8;
|
||||
|
||||
/** Default external crystal oscillator frequency. */
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f;
|
||||
|
||||
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(uint8_t dev_addr, const float crystal_freq);
|
||||
~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;
|
||||
float xtal_freq = ATHENS_XTAL;
|
||||
|
||||
uint8_t regs[ATHENS_NUM_REGS] = {};
|
||||
};
|
||||
|
||||
#endif // ATHENS_H
|
||||
@@ -0,0 +1,625 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/mmiodevice.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;
|
||||
}
|
||||
|
||||
void DMAChannel::set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb) {
|
||||
this->in_cb = in_cb;
|
||||
this->out_cb = out_cb;
|
||||
this->flush_cb = flush_cb;
|
||||
}
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
|
||||
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
|
||||
if (is_writable) *is_writable = res.is_writable;
|
||||
DMACmd* cmd_host = (DMACmd*)res.host_va;
|
||||
p_cmd->req_count = READ_WORD_LE_A(&cmd_host->req_count);
|
||||
p_cmd->cmd_bits = cmd_host->cmd_bits;
|
||||
p_cmd->cmd_key = cmd_host->cmd_key;
|
||||
p_cmd->address = READ_DWORD_LE_A(&cmd_host->address);
|
||||
p_cmd->cmd_arg = READ_DWORD_LE_A(&cmd_host->cmd_arg);
|
||||
p_cmd->res_count = READ_WORD_LE_A(&cmd_host->res_count);
|
||||
p_cmd->xfer_stat = READ_WORD_LE_A(&cmd_host->xfer_stat);
|
||||
return cmd_host;
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
MapDmaResult res;
|
||||
|
||||
if (this->cmd_in_progress) {
|
||||
// return current command if there is data to transfer
|
||||
if (this->queue_len)
|
||||
return this->cur_cmd;
|
||||
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
bool cmd_is_writable;
|
||||
DMACmd *cmd_host = fetch_cmd(this->cmd_ptr, &cmd_struct, &cmd_is_writable);
|
||||
|
||||
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, "%s: Key > 0 not implemented", this->get_name().c_str());
|
||||
break;
|
||||
}
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
if (this->queue_len) {
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->res_count = 0;
|
||||
this->cmd_in_progress = true;
|
||||
switch (this->cur_cmd) {
|
||||
case DBDMA_Cmd::OUTPUT_MORE:
|
||||
case DBDMA_Cmd::OUTPUT_LAST:
|
||||
this->xfer_to_device();
|
||||
if (this->out_cb)
|
||||
this->out_cb();
|
||||
break;
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
this->xfer_from_device();
|
||||
if (this->in_cb)
|
||||
this->in_cb();
|
||||
break;
|
||||
}
|
||||
} else
|
||||
this->finish_cmd();
|
||||
break;
|
||||
case DBDMA_Cmd::STORE_QUAD:
|
||||
if ((cmd_struct.cmd_key & 7) != 6)
|
||||
LOG_F(ERROR, "%s: Invalid key %d in STORE_QUAD", this->get_name().c_str(),
|
||||
cmd_struct.cmd_key & 7);
|
||||
this->xfer_quad(&cmd_struct, nullptr);
|
||||
break;
|
||||
case DBDMA_Cmd::LOAD_QUAD:
|
||||
if ((cmd_struct.cmd_key & 7) != 6) {
|
||||
LOG_F(ERROR, "%s: Invalid key %d in LOAD_QUAD", this->get_name().c_str(),
|
||||
cmd_struct.cmd_key & 7);
|
||||
}
|
||||
if (!cmd_is_writable)
|
||||
LOG_F(ERROR, "%s: DMACmd is not writeable!", this->get_name().c_str());
|
||||
this->xfer_quad(&cmd_struct, cmd_host);
|
||||
break;
|
||||
case DBDMA_Cmd::NOP:
|
||||
this->finish_cmd();
|
||||
break;
|
||||
case DBDMA_Cmd::STOP:
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
this->cmd_in_progress = false;
|
||||
this->finish_cmd();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: Unsupported DMA command 0x%X", this->get_name().c_str(),
|
||||
this->cur_cmd);
|
||||
this->ch_stat |= CH_STAT_DEAD;
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
}
|
||||
|
||||
return this->cur_cmd;
|
||||
}
|
||||
|
||||
void DMAChannel::finish_cmd() {
|
||||
bool branch_taken = false;
|
||||
|
||||
// obtain real pointer to the descriptor of the command to be finished
|
||||
MapDmaResult res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
uint8_t *cmd_desc = res.host_va;
|
||||
|
||||
// get command code
|
||||
this->cur_cmd = cmd_desc[3] >> 4;
|
||||
|
||||
// all commands except STOP update cmd.xferStatus and
|
||||
// perform actions under control of "i" interrupt, "b" branch, and "w" wait bits
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
// react to cmd.w (wait) bits
|
||||
if (cmd_desc[2] & 3) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 3) != 3) {
|
||||
uint16_t wt_mask = this->wait_select >> 16;
|
||||
cond = (this->ch_stat & wt_mask) == (this->wait_select & wt_mask);
|
||||
if ((cmd_desc[2] & 3) == 2) {
|
||||
cond = !cond; // wait if cond = false
|
||||
}
|
||||
}
|
||||
|
||||
if (cond)
|
||||
return;
|
||||
}
|
||||
|
||||
this->ch_stat &= ~CH_STAT_BT;
|
||||
|
||||
// react to cmd.b (branch) bits
|
||||
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) {
|
||||
cond = !cond; // branch if cond = false
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
branch_taken = true;
|
||||
this->ch_stat |= CH_STAT_BT;
|
||||
}
|
||||
}
|
||||
|
||||
if (res.is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
}
|
||||
|
||||
this->ch_stat &= ~(CH_STAT_FLUSH | CH_STAT_BT);
|
||||
|
||||
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
|
||||
this->res_count = 0;
|
||||
}
|
||||
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP && !branch_taken)
|
||||
this->cmd_ptr += 16;
|
||||
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
this->update_irq();
|
||||
}
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host) {
|
||||
MapDmaResult res;
|
||||
uint32_t addr;
|
||||
|
||||
// parse and fix reqCount
|
||||
uint32_t xfer_size = cmd_desc->req_count & 7;
|
||||
if (xfer_size & 4) {
|
||||
xfer_size = 4;
|
||||
} else if (xfer_size & 2) {
|
||||
xfer_size = 2;
|
||||
} else {
|
||||
xfer_size = 1;
|
||||
}
|
||||
this->res_count = cmd_desc->req_count; // this is the value that gets written to cmd.resCount
|
||||
|
||||
addr = cmd_desc->address;
|
||||
if (addr & (xfer_size - 1)) {
|
||||
LOG_F(ERROR, "%s: QUAD address 0x%08x is not aligned!", this->get_name().c_str(), addr);
|
||||
addr &= ~(xfer_size - 1);
|
||||
}
|
||||
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
|
||||
// prepare data pointers and perform data transfer
|
||||
if (!cmd_host) {
|
||||
if (res.type & RT_MMIO) {
|
||||
res.dev_obj->write(res.dev_base, addr - res.dev_base, cmd_desc->cmd_arg, xfer_size);
|
||||
} else if (res.is_writable) {
|
||||
switch (xfer_size) {
|
||||
case 1: *res.host_va = cmd_desc->cmd_arg; break;
|
||||
case 2: WRITE_WORD_LE_A(res.host_va, cmd_desc->cmd_arg); break;
|
||||
case 4: WRITE_DWORD_LE_A(res.host_va, cmd_desc->cmd_arg); break;
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "SOS: DMA access is not to RAM %08X!\n", addr);
|
||||
}
|
||||
} else {
|
||||
uint32_t value;
|
||||
if (res.type & RT_MMIO) {
|
||||
value = res.dev_obj->read(res.dev_base, addr - res.dev_base, xfer_size);
|
||||
} else {
|
||||
switch (xfer_size) {
|
||||
case 1: value = *res.host_va; break;
|
||||
case 2: value = READ_WORD_LE_A(res.host_va); break;
|
||||
case 4: value = READ_DWORD_LE_A(res.host_va); break;
|
||||
default: value = 0; break;
|
||||
}
|
||||
}
|
||||
WRITE_DWORD_LE_A(&cmd_host->cmd_arg, value);
|
||||
}
|
||||
|
||||
if (cmd_desc->cmd_bits & 0xC)
|
||||
ABORT_F("%s: cmd_bits.b should be zero for LOAD/STORE_QUAD!",
|
||||
this->get_name().c_str());
|
||||
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::update_irq() {
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
MapDmaResult res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
uint8_t *cmd_desc = res.host_va;
|
||||
|
||||
// STOP doesn't generate interrupts
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
// react to cmd.i (interrupt) bits
|
||||
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) {
|
||||
cond = !cond; // generate interrupt if cond = false
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
if (int_ctrl) {
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
} else
|
||||
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
uint32_t result = 0;
|
||||
|
||||
switch (offset & ~3) {
|
||||
case DMAReg::CH_CTRL:
|
||||
result = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
result = this->ch_stat;
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
result = this->cmd_ptr;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
|
||||
this->get_name().c_str(), offset);
|
||||
}
|
||||
|
||||
if ((offset & 3) || size != 4)
|
||||
return BYTESWAP_SIZED(result >> ((offset & 3) * 8), size);
|
||||
else
|
||||
return BYTESWAP_32(result);
|
||||
}
|
||||
|
||||
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
uint16_t mask, old_stat, new_stat;
|
||||
|
||||
if (size != 4) {
|
||||
ABORT_F("%s: non-DWORD writes to a DMA channel not supported",
|
||||
this->get_name().c_str());
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
old_stat = this->ch_stat;
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
mask = value >> 16;
|
||||
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~(mask & 0xC0FF));
|
||||
LOG_F(9, "%s: New ChannelStatus value = 0x%X", this->get_name().c_str(), new_stat);
|
||||
|
||||
// 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) {
|
||||
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST &&
|
||||
this->flush_cb && (new_stat & CH_STAT_ACTIVE) &&
|
||||
!(this->ch_stat & CH_STAT_DEAD)) {
|
||||
this->flush_cb();
|
||||
} else {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
|
||||
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)) {
|
||||
if (new_stat & CH_STAT_WAKE) {
|
||||
new_stat |= CH_STAT_ACTIVE;
|
||||
this->ch_stat = new_stat;
|
||||
this->resume();
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: Attempt to clear wake status bit 0x%04x", this->get_name().c_str(), CH_STAT_WAKE);
|
||||
}
|
||||
} else if ((new_stat & CH_STAT_PAUSE) != (old_stat & CH_STAT_PAUSE)) {
|
||||
if (new_stat & CH_STAT_PAUSE) {
|
||||
new_stat &= ~CH_STAT_ACTIVE;
|
||||
this->ch_stat = new_stat;
|
||||
this->pause();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_HI:
|
||||
if (value != 0) {
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
break;
|
||||
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, "%s: CommandPtrLo set to 0x%X", this->get_name().c_str(),
|
||||
this->cmd_ptr);
|
||||
}
|
||||
break;
|
||||
case DMAReg::INT_SELECT:
|
||||
this->int_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
case DMAReg::BRANCH_SELECT:
|
||||
this->branch_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
case DMAReg::WAIT_SELECT:
|
||||
this->wait_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write at 0x%X",
|
||||
this->get_name().c_str(), offset);
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_from_device() {
|
||||
if (this->dev_obj == nullptr)
|
||||
return;
|
||||
|
||||
this->xfer_dir = DMA_DIR_FROM_DEV;
|
||||
|
||||
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
|
||||
this->queue_len = 0;
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_to_device() {
|
||||
if (this->dev_obj == nullptr)
|
||||
return;
|
||||
|
||||
this->xfer_dir = DMA_DIR_TO_DEV;
|
||||
|
||||
if (!this->dev_obj->xfer_to(this->queue_data, this->queue_len)) {
|
||||
this->queue_len = 0;
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Dead/idle channel -> no more data", this->get_name().c_str());
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
// 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, "%s: Return req_len = %d data", this->get_name().c_str(), req_len);
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = req_len;
|
||||
this->queue_len -= req_len;
|
||||
this->res_count += req_len;
|
||||
this->queue_data += req_len;
|
||||
} else { // return less data than req_len
|
||||
LOG_F(9, "%s: Return queue_len = %d data", this->get_name().c_str(),
|
||||
this->queue_len);
|
||||
*p_data = this->queue_data;
|
||||
*avail_len = this->queue_len;
|
||||
this->res_count += this->queue_len;
|
||||
this->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, "%s: attempt to push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
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->res_count += len;
|
||||
this->queue_len -= len;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program if the buffer became exhausted
|
||||
if (!this->queue_len) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DMAChannel::end_pull_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::end_push_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
LOG_F(WARNING, "%s: Attempt to end push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_out_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool DMAChannel::is_in_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, "%s: Cannot start DMA channel, PAUSE bit is set",
|
||||
this->get_name().c_str());
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE; // TODO: Test this in Open Firmware.
|
||||
return;
|
||||
}
|
||||
|
||||
this->queue_len = 0;
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
|
||||
if (this->start_cb)
|
||||
this->start_cb();
|
||||
|
||||
// some DBDMA programs contain commands that don't transfer data
|
||||
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
|
||||
// We thus interprete the DBDMA program until a data transfer between
|
||||
// a device and memory is queued or the channel becomes idle/dead.
|
||||
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
|
||||
(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
if (this->ch_stat & CH_STAT_PAUSE) {
|
||||
LOG_F(WARNING, "%s: Cannot resume DMA channel, PAUSE bit is set",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s: Resuming DMA channel", this->get_name().c_str());
|
||||
|
||||
// some DBDMA programs contain commands that don't transfer data
|
||||
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
|
||||
// We thus interprete the DBDMA program until a data transfer between
|
||||
// a device and memory is queued or the channel becomes idle/dead.
|
||||
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
|
||||
(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::abort() {
|
||||
LOG_F(9, "%s: Aborting DMA channel", this->get_name().c_str());
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "%s: Pausing DMA channel", this->get_name().c_str());
|
||||
if (this->stop_cb)
|
||||
this->stop_cb();
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation.
|
||||
|
||||
Official documentation can be found in the fifth chapter of the book
|
||||
"Macintosh Technology in the Common Hardware Reference Platform"
|
||||
by Apple Computer, Inc.
|
||||
*/
|
||||
|
||||
#ifndef DB_DMA_H
|
||||
#define DB_DMA_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
class InterruptCtrl;
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_HI = 8, // not implemented
|
||||
CMD_PTR_LO = 12,
|
||||
INT_SELECT = 16,
|
||||
BRANCH_SELECT = 20,
|
||||
WAIT_SELECT = 24,
|
||||
// TANSFER_MODES = 28,
|
||||
// DATA_2_PTR_HI = 32, // not implemented
|
||||
// DATA_2_PTR_LO = 36,
|
||||
// RESERVED_1 = 40,
|
||||
// ADDRESS_HI = 44,
|
||||
// RESERVED_2_0 = 48,
|
||||
// RESERVED_2_1 = 52,
|
||||
// RESERVED_2_2 = 56,
|
||||
// RESERVED_2_3 = 60,
|
||||
// UNIMPLEMENTED = 64,
|
||||
// UNDEFINED = 128,
|
||||
};
|
||||
|
||||
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
||||
enum : uint16_t {
|
||||
CH_STAT_S0 = 0x0001, // general purpose status and control
|
||||
CH_STAT_S1 = 0x0002, // general purpose status and control
|
||||
CH_STAT_S2 = 0x0004, // general purpose status and control
|
||||
CH_STAT_S3 = 0x0008, // general purpose status and control
|
||||
CH_STAT_S4 = 0x0010, // general purpose status and control
|
||||
CH_STAT_S5 = 0x0020, // general purpose status and control
|
||||
CH_STAT_S6 = 0x0040, // general purpose status and control
|
||||
CH_STAT_S7 = 0x0080, // general purpose status and control
|
||||
CH_STAT_BT = 0x0100, // hardware status bit
|
||||
CH_STAT_ACTIVE = 0x0400, // hardware status bit
|
||||
CH_STAT_DEAD = 0x0800, // hardware status bit
|
||||
CH_STAT_WAKE = 0x1000, // command bit set by software and cleared by hardware once the action has been performed
|
||||
CH_STAT_FLUSH = 0x2000, // command bit set by software and cleared by hardware once the action has been performed
|
||||
CH_STAT_PAUSE = 0x4000, // control bit set and cleared by software
|
||||
CH_STAT_RUN = 0x8000 // control bit set and cleared by software
|
||||
};
|
||||
|
||||
/** DBDMA command (DBDMA spec, 5.6.1) - all fields are little-endian! */
|
||||
typedef struct DMACmd {
|
||||
uint16_t req_count;
|
||||
uint8_t cmd_bits; // wait: & 3, branch: & 0xC, interrupt: & 0x30, reserved: & 0xc0
|
||||
uint8_t cmd_key; // key: & 7, reserved: & 8, cmd: >> 4
|
||||
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 {
|
||||
public:
|
||||
DMAChannel(std::string name) : DmaBidirChannel(name) {}
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
void set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
|
||||
|
||||
bool is_out_active();
|
||||
bool is_in_active();
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data);
|
||||
int push_data(const char* src_ptr, int len);
|
||||
int get_pull_data_remaining() { return this->queue_len; }
|
||||
int get_push_data_remaining() { return this->queue_len; }
|
||||
void end_pull_data();
|
||||
void end_push_data();
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
this->irq_id = irq_id;
|
||||
};
|
||||
|
||||
protected:
|
||||
DMACmd* fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable);
|
||||
uint8_t interpret_cmd(void);
|
||||
void finish_cmd();
|
||||
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
|
||||
void update_irq();
|
||||
void xfer_from_device();
|
||||
void xfer_to_device();
|
||||
|
||||
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
|
||||
std::function<void(void)> in_cb = nullptr; // DMA channel in callback
|
||||
std::function<void(void)> out_cb = nullptr; // DMA channel out callback
|
||||
std::function<void(void)> flush_cb = nullptr; // DMA channel flush callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
uint32_t queue_len = 0;
|
||||
uint8_t* queue_data = 0;
|
||||
uint32_t res_count = 0;
|
||||
uint32_t int_select = 0;
|
||||
uint32_t branch_select = 0;
|
||||
uint32_t wait_select = 0;
|
||||
|
||||
bool cmd_in_progress = false;
|
||||
uint8_t cur_cmd;
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif // DB_DMA_H
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Core definitions for direct memory access (DMA) emulation. */
|
||||
|
||||
#ifndef DMA_CORE_H
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
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:
|
||||
DmaOutChannel(std::string name) { this->name = name; };
|
||||
|
||||
virtual bool is_out_active() { return true; };
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
virtual int get_pull_data_remaining() { return 1; };
|
||||
virtual void end_pull_data() { };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class DmaInChannel {
|
||||
public:
|
||||
DmaInChannel(std::string name) { this->name = name; };
|
||||
|
||||
virtual bool is_in_active() { return true; };
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual int get_push_data_remaining() { return 1; };
|
||||
virtual void end_push_data() { };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// Base class for bidirectional DMA channels.
|
||||
class DmaBidirChannel : public DmaOutChannel, public DmaInChannel {
|
||||
public:
|
||||
DmaBidirChannel(std::string name) : DmaOutChannel(name + " Out"),
|
||||
DmaInChannel(name + std::string(" In")) { this->name = name; };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// ---------------------- New DMA API -------------------------
|
||||
enum DmaMsg : unsigned {
|
||||
CH_START = 1,
|
||||
CH_STOP,
|
||||
DATA_AVAIL,
|
||||
};
|
||||
|
||||
enum XferDir : unsigned {
|
||||
DMA_DIR_UNDEF = 0,
|
||||
DMA_DIR_TO_DEV,
|
||||
DMA_DIR_FROM_DEV,
|
||||
};
|
||||
|
||||
class DmaChannel;
|
||||
|
||||
class DmaDevice {
|
||||
public:
|
||||
DmaDevice() = default;
|
||||
~DmaDevice() = default;
|
||||
|
||||
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
|
||||
void notify(DmaMsg msg) {};
|
||||
virtual int xfer_from(uint8_t *buf, int len) { return len; };
|
||||
virtual int xfer_to(uint8_t *buf, int len) { return len; };
|
||||
|
||||
protected:
|
||||
DmaChannel* channel_obj = nullptr;
|
||||
};
|
||||
|
||||
class DmaChannel {
|
||||
public:
|
||||
DmaChannel() = default;
|
||||
~DmaChannel() = default;
|
||||
|
||||
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
|
||||
void notify(DmaMsg msg) {};
|
||||
|
||||
protected:
|
||||
DmaDevice* dev_obj = nullptr;
|
||||
XferDir xfer_dir = DMA_DIR_UNDEF;
|
||||
};
|
||||
|
||||
/*
|
||||
TODO: write CONNECT macro that
|
||||
- constructs both DmaChannel and DmaDevice objects
|
||||
- calls connect() method on both objects
|
||||
- initializes DMA interrupts
|
||||
*/
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
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 HW_COMPONENT_H
|
||||
#define HW_COMPONENT_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** types of different HW components */
|
||||
enum HWCompType : uint64_t {
|
||||
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
|
||||
IOBUS_HOST = 1ULL << 14, // IOBus host
|
||||
IOBUS_DEV = 1ULL << 15, // IOBus 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_HOST = 1ULL << 24, // IDE host controller
|
||||
IDE_DEV = 1ULL << 25, // IDE device
|
||||
SND_CODEC = 1ULL << 30, // sound codec
|
||||
SND_SERVER = 1ULL << 31, // host sound server
|
||||
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
|
||||
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
|
||||
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
|
||||
};
|
||||
|
||||
/** 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,118 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 : uint32_t {
|
||||
INT_UNKNOWN = 0,
|
||||
VIA_CUDA,
|
||||
VIA2,
|
||||
SCSI_MESH,
|
||||
SCSI_CURIO,
|
||||
SWIM3,
|
||||
ESCC,
|
||||
SCCA,
|
||||
SCCB,
|
||||
ETHERNET,
|
||||
NMI,
|
||||
EXT1,
|
||||
IDE0,
|
||||
IDE1,
|
||||
DAVBUS,
|
||||
PERCH1,
|
||||
PERCH2,
|
||||
PCI_A,
|
||||
PCI_B,
|
||||
PCI_C,
|
||||
PCI_D,
|
||||
PCI_E,
|
||||
PCI_F,
|
||||
PCI_GPU,
|
||||
PCI_PERCH,
|
||||
BANDIT1,
|
||||
BANDIT2,
|
||||
CONTROL,
|
||||
SIXTY6,
|
||||
PLANB,
|
||||
VCI,
|
||||
PLATINUM,
|
||||
DMA_ALL,
|
||||
DMA_SCSI_MESH,
|
||||
DMA_SCSI_CURIO,
|
||||
DMA_SWIM3,
|
||||
DMA_IDE0,
|
||||
DMA_IDE1,
|
||||
DMA_SCCA_Tx,
|
||||
DMA_SCCA_Rx,
|
||||
DMA_SCCB_Tx,
|
||||
DMA_SCCB_Rx,
|
||||
DMA_DAVBUS_Tx,
|
||||
DMA_DAVBUS_Rx,
|
||||
DMA_ETHERNET_Tx,
|
||||
DMA_ETHERNET_Rx,
|
||||
FIREWIRE,
|
||||
PCI_J12,
|
||||
PCI_J11,
|
||||
PCI_J10,
|
||||
PCI_J9,
|
||||
ATA,
|
||||
USB,
|
||||
PIPPIN_E,
|
||||
PIPPIN_F,
|
||||
ZIVA,
|
||||
PCI_CARDBUS,
|
||||
MEDIA_BAY,
|
||||
SLOT_ALL,
|
||||
SLOT_0,
|
||||
SLOT_1,
|
||||
SLOT_2,
|
||||
SLOT_PDS,
|
||||
SLOT_VDS,
|
||||
VBL,
|
||||
};
|
||||
|
||||
/** Base class for interrupt controllers. */
|
||||
class InterruptCtrl {
|
||||
public:
|
||||
InterruptCtrl() = default;
|
||||
virtual ~InterruptCtrl() = default;
|
||||
|
||||
// register interrupt sources for a device
|
||||
virtual uint64_t register_dev_int(IntSrc src_id) = 0;
|
||||
virtual uint64_t register_dma_int(IntSrc src_id) = 0;
|
||||
|
||||
// acknowledge HW interrupt
|
||||
virtual void ack_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
|
||||
virtual void ack_dma_int(uint64_t irq_id, uint8_t irq_line_state) = 0;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
InterruptCtrl *int_ctrl_obj;
|
||||
uint64_t irq_id;
|
||||
} IntDetails;
|
||||
|
||||
#endif // HW_INTERRUPT_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,27 +27,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
public:
|
||||
virtual void start_transaction() = 0;
|
||||
virtual void start_transaction() = 0;
|
||||
virtual bool send_subaddress(uint8_t sub_addr) = 0;
|
||||
virtual bool send_byte(uint8_t data) = 0;
|
||||
virtual bool receive_byte(uint8_t *p_data) = 0;
|
||||
virtual bool send_byte(uint8_t data) = 0;
|
||||
virtual bool receive_byte(uint8_t* p_data) = 0;
|
||||
};
|
||||
|
||||
/** Base class for I2C hosts */
|
||||
class I2CBus {
|
||||
public:
|
||||
I2CBus() { std::memset(this->dev_list, 0, sizeof(this->dev_list)); };
|
||||
~I2CBus() { std::memset(this->dev_list, 0, sizeof(this->dev_list)); };
|
||||
I2CBus() {
|
||||
std::memset(this->dev_list, 0, sizeof(this->dev_list));
|
||||
};
|
||||
virtual ~I2CBus() = default;
|
||||
|
||||
virtual void register_device(uint8_t dev_addr, I2CDevice *dev_obj) {
|
||||
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
|
||||
if (this->dev_list[dev_addr]) {
|
||||
throw std::invalid_argument(std::string("I2C address already taken!"));
|
||||
}
|
||||
@@ -78,7 +82,7 @@ public:
|
||||
return this->dev_list[dev_addr]->send_byte(data);
|
||||
};
|
||||
|
||||
virtual bool receive_byte(uint8_t dev_addr, uint8_t *p_data) {
|
||||
virtual bool receive_byte(uint8_t dev_addr, uint8_t* p_data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
@@ -86,7 +90,7 @@ public:
|
||||
};
|
||||
|
||||
protected:
|
||||
I2CDevice *dev_list[128]; /* list of registered I2C devices */
|
||||
I2CDevice* dev_list[128]; /* list of registered I2C devices */
|
||||
};
|
||||
|
||||
#endif /* I2C_H */
|
||||
@@ -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 Generic PROM device programmable over I2C. */
|
||||
|
||||
#include <devices/common/i2c/i2cprom.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
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 MACHINE_ID_H
|
||||
#define MACHINE_ID_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
@file Contains definitions for Power Macintosh machine ID registers.
|
||||
|
||||
The machine ID register is a memory-based register containing hardcoded
|
||||
values the system software can read to identify machine/board it's running on.
|
||||
|
||||
Register location and value meaning are board-dependent.
|
||||
*/
|
||||
|
||||
/**
|
||||
Machine ID register for NuBus Power Macs.
|
||||
It's located at physical address 0x5FFFFFFC and contains four bytes:
|
||||
+0 uint16_t signature = 0xA55A
|
||||
+1 uint8_t machine_type (3 - Power Mac)
|
||||
+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) {
|
||||
if (size == 4 && offset == 0) {
|
||||
return *(uint32_t*)this->id;
|
||||
}
|
||||
if (size == 1 && offset < 4) {
|
||||
return this->id[offset];
|
||||
}
|
||||
ABORT_F("NubusMacID: invalid read size %d, offset %d!", size, offset);
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint8_t id[4];
|
||||
};
|
||||
|
||||
/**
|
||||
TNT-style machines and derivatives provide two board registers
|
||||
telling whether some particular piece of HW is installed or not.
|
||||
Both board registers are attached to the IOBus of the I/O controller.
|
||||
See machines/machinetnt.cpp for further details.
|
||||
**/
|
||||
class BoardRegister : public HWComponent, public IobusDevice {
|
||||
public:
|
||||
BoardRegister(std::string name, const uint16_t data) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IOBUS_DEV);
|
||||
this->data = data;
|
||||
};
|
||||
~BoardRegister() = default;
|
||||
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return this->data;
|
||||
};
|
||||
|
||||
// appears read-only to guest
|
||||
void iodev_write(uint32_t address, uint16_t value) {};
|
||||
|
||||
void update_bits(const uint16_t val, const uint16_t mask) {
|
||||
this->data = (this->data & ~mask) | (val & mask);
|
||||
};
|
||||
|
||||
private:
|
||||
uint16_t data;
|
||||
};
|
||||
|
||||
/**
|
||||
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.
|
||||
See machines/machinegossamer.cpp for further details.
|
||||
*/
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
GossamerID(const uint16_t id) {
|
||||
this->id = id;
|
||||
this->name = "Machine-id";
|
||||
supports_types(HWCompType::MMIO_DEV);
|
||||
};
|
||||
~GossamerID() = default;
|
||||
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return ((offset == 4 && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
};
|
||||
|
||||
#endif // MACHINE_ID_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,16 +22,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MMIO_DEVICE_H
|
||||
#define MMIO_DEVICE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include "hwcomponent.h"
|
||||
|
||||
/** Abstract class representing a simple, memory-mapped I/O device */
|
||||
class MMIODevice : public HWComponent {
|
||||
public:
|
||||
virtual uint32_t read(uint32_t reg_start, uint32_t offset, int size) = 0;
|
||||
virtual void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) = 0;
|
||||
virtual ~MMIODevice() = default;
|
||||
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;
|
||||
};
|
||||
|
||||
#define SIZE_ARG(size) (size == 4 ? 'l' : size == 2 ? 'w' : \
|
||||
size == 1 ? 'b' : '0' + size)
|
||||
|
||||
#endif /* MMIO_DEVICE_H */
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/nubus/nubusutils.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
uint32_t calculate_rom_crc(uint8_t *data_ptr, int length)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
// rotate sum left by one bit
|
||||
if (sum & 0x80000000UL)
|
||||
sum = (sum << 1) | 1;
|
||||
else
|
||||
sum = (sum << 1) | 0;
|
||||
sum += data_ptr[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
int load_declaration_rom(const std::string rom_path, int slot_num)
|
||||
{
|
||||
std::ifstream rom_file;
|
||||
|
||||
int result = 0;
|
||||
|
||||
try {
|
||||
rom_file.open(rom_path, std::ios::in | std::ios::binary);
|
||||
if (rom_file.fail())
|
||||
throw std::runtime_error("could not open declaration ROM image " + rom_path);
|
||||
|
||||
// determine image size
|
||||
rom_file.seekg(0, std::ios::end);
|
||||
uint64_t rom_size = rom_file.tellg();
|
||||
|
||||
if (rom_size > 16 * 1024 * 1024)
|
||||
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
|
||||
std::to_string(rom_size) + " is too large");
|
||||
|
||||
// load it
|
||||
auto rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[rom_size]);
|
||||
rom_file.seekg(0, std::ios::beg);
|
||||
rom_file.read((char *)rom_data.get(), rom_size);
|
||||
|
||||
// verify image data
|
||||
uint8_t byte_lane = rom_data[rom_size - 1];
|
||||
if ((byte_lane & 0xF) != ((byte_lane >> 4) ^ 0xF))
|
||||
throw std::runtime_error("declaration ROM image " + rom_path +
|
||||
" has invalid byte lane value");
|
||||
|
||||
if (READ_DWORD_BE_A(&rom_data[rom_size - 6]) != 0x5A932BC7UL)
|
||||
throw std::runtime_error("declaration ROM image " + rom_path +
|
||||
" has invalid test pattern");
|
||||
|
||||
if (rom_data[rom_size - 7] != 1)
|
||||
throw std::runtime_error("declaration ROM image " + rom_path +
|
||||
" has unsupported format");
|
||||
|
||||
uint32_t crc = READ_DWORD_BE_A(&rom_data[rom_size - 12]);
|
||||
int hdr_length = READ_DWORD_BE_A(&rom_data[rom_size - 16]);
|
||||
|
||||
// patch the CRC field of the format header to 0
|
||||
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], 0);
|
||||
|
||||
uint32_t test_crc = calculate_rom_crc(rom_data.get(), hdr_length);
|
||||
|
||||
// restore the CRC field value
|
||||
WRITE_DWORD_BE_A(&rom_data[rom_size - 12], crc);
|
||||
|
||||
if (test_crc != crc) {
|
||||
std::stringstream err;
|
||||
err << "declaration ROM image " + rom_path + " has invalid CRC, expected = 0x"
|
||||
<< std::hex << crc << ", got = 0x" << std::hex << test_crc;
|
||||
throw std::runtime_error(err.str());
|
||||
}
|
||||
|
||||
int lanes_used = 0;
|
||||
|
||||
// count meaningful lanes in a data quad
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (byte_lane & (1 << i))
|
||||
lanes_used++;
|
||||
}
|
||||
|
||||
// padded_len is the size in bytes of all pages needed to contain all the bytes of the ROM
|
||||
uint32_t padded_len =
|
||||
uint32_t(((rom_size * 4 + lanes_used - 1) / lanes_used + 4095) / 4096 * 4096);
|
||||
|
||||
if (padded_len > 16 * 1024 * 1024)
|
||||
throw std::runtime_error("declaration ROM image " + rom_path + " size " +
|
||||
std::to_string(rom_size) + " is too large");
|
||||
|
||||
// calculate starting physical address of the ROM
|
||||
uint32_t rom_phys_start = (0xF0FFFFFFUL | ((slot_num & 0xF) << 24)) - padded_len + 1;
|
||||
|
||||
auto mem_crtl = dynamic_cast<MemCtrlBase*>(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
if (!mem_crtl->add_rom_region(rom_phys_start, padded_len))
|
||||
throw std::runtime_error("could not allocate ROM space for declaration ROM image " +
|
||||
rom_path);
|
||||
|
||||
int data_pos = int(rom_size) - 1;
|
||||
|
||||
auto new_data = std::unique_ptr<uint8_t[]> (new uint8_t[padded_len]);
|
||||
|
||||
// prepare new ROM data by copying over used lanes
|
||||
// and padding unused lanes with 0xFF
|
||||
// NOTE: speed uncritical - don't optimize!
|
||||
for (int i = padded_len - 1; i >= 0; ) {
|
||||
for (int b = 8; i>= 0 && b != 0; b >>= 1) {
|
||||
if (data_pos >= 0 && (byte_lane & b))
|
||||
new_data[i--] = rom_data[data_pos--];
|
||||
else
|
||||
new_data[i--] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
// move padded ROM data to the memory region
|
||||
mem_crtl->set_data(rom_phys_start, new_data.get(), padded_len);
|
||||
}
|
||||
catch (const std::exception& exc) {
|
||||
LOG_F(ERROR, "load_declaration_rom failed: %s", exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
rom_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,46 +1,30 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The uniquely Gekko opcodes for the processor - ppcgekkoopcodes.cpp
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include "ppcemu.h"
|
||||
|
||||
void ppc_psq_l(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_lu(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_st(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_stu(){
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NUBUS_UTILS_H
|
||||
#define NUBUS_UTILS_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
int load_declaration_rom(const std::string rom_path, int slot_num);
|
||||
|
||||
#endif // NUBUS_UTILS_H
|
||||
@@ -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 <thirdparty/loguru/loguru.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include "nvram.h"
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/** @file Non-volatile RAM implementation.
|
||||
*/
|
||||
@@ -36,60 +39,67 @@ static char NVRAM_FILE_ID[] = "DINGUSPPCNVRAM";
|
||||
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
{
|
||||
this->name = "NVRAM";
|
||||
|
||||
supports_types(HWCompType::NVRAM);
|
||||
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
this->storage = new uint8_t[ram_size];
|
||||
// allocate memory storage and fill it with zeroes
|
||||
this->storage = std::unique_ptr<uint8_t[]>(new uint8_t[ram_size] ());
|
||||
|
||||
this->init();
|
||||
}
|
||||
|
||||
NVram::~NVram()
|
||||
{
|
||||
NVram::~NVram() {
|
||||
this->save();
|
||||
if (this->storage)
|
||||
delete this->storage;
|
||||
}
|
||||
|
||||
uint8_t NVram::read_byte(uint32_t offset)
|
||||
{
|
||||
uint8_t NVram::read_byte(uint32_t offset) {
|
||||
return (this->storage[offset]);
|
||||
}
|
||||
|
||||
void NVram::write_byte(uint32_t offset, uint8_t val)
|
||||
{
|
||||
void NVram::write_byte(uint32_t offset, uint8_t val) {
|
||||
this->storage[offset] = val;
|
||||
}
|
||||
|
||||
void NVram::init() {
|
||||
char sig[sizeof(NVRAM_FILE_ID)];
|
||||
char sig[sizeof(NVRAM_FILE_ID)];
|
||||
uint16_t data_size;
|
||||
|
||||
ifstream f(this->file_name, ios::in | ios::binary);
|
||||
|
||||
if (f.fail() || !f.read(sig, sizeof(NVRAM_FILE_ID)) || \
|
||||
!f.read((char *)&data_size, sizeof(data_size)) || \
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || \
|
||||
data_size != this->ram_size || \
|
||||
!f.read((char *)this->storage, this->ram_size))
|
||||
{
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file. \n");
|
||||
memset(this->storage, 0, sizeof(this->ram_size));
|
||||
if (f.fail() || !f.read(sig, sizeof(NVRAM_FILE_ID)) ||
|
||||
!f.read((char*)&data_size, sizeof(data_size)) ||
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || data_size != this->ram_size ||
|
||||
!f.read((char*)this->storage.get(), this->ram_size)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file \"%s\".", this->file_name.c_str());
|
||||
memset(this->storage.get(), 0, this->ram_size);
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
void NVram::save()
|
||||
{
|
||||
void NVram::save() {
|
||||
if (is_deterministic) {
|
||||
LOG_F(INFO, "Skipping NVRAM write to \"%s\" in deterministic mode", this->file_name.c_str());
|
||||
return;
|
||||
}
|
||||
ofstream f(this->file_name, ios::out | ios::binary);
|
||||
|
||||
/* write file identification */
|
||||
f.write(NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID));
|
||||
f.write((char *)&this->ram_size, sizeof(this->ram_size));
|
||||
f.write((char*)&this->ram_size, sizeof(this->ram_size));
|
||||
|
||||
/* write NVRAM content */
|
||||
f.write((char *)this->storage, this->ram_size);
|
||||
f.write((char*)this->storage.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,8 +22,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef NVRAM_H
|
||||
#define NVRAM_H
|
||||
|
||||
#include <string>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** @file Non-volatile RAM emulation.
|
||||
|
||||
@@ -31,22 +34,25 @@ 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);
|
||||
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();
|
||||
void init();
|
||||
void save();
|
||||
};
|
||||
|
||||
#endif /* NVRAM_H */
|
||||
@@ -0,0 +1,606 @@
|
||||
/*
|
||||
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 <devices/common/nvram.h>
|
||||
#include <endianswap.h>
|
||||
#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;
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return 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();
|
||||
|
||||
this->data_length = 0;
|
||||
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
for (int pos = 0; pos < 4096;) {
|
||||
char *pname = (char *)&this->buf[pos];
|
||||
bool got_name = false;
|
||||
|
||||
// scan property name until '=' is encountered
|
||||
// or max length is reached
|
||||
for (len = 0; ; pos++, len++) {
|
||||
if (len >= 32) {
|
||||
cout << "name > 31 chars" << endl;
|
||||
break;
|
||||
}
|
||||
if (pos >= 4096) {
|
||||
cout << "no = sign before end of partition" << endl;
|
||||
break;
|
||||
}
|
||||
if (pname[len] == '=') {
|
||||
if (len) {
|
||||
got_name = true;
|
||||
}
|
||||
else {
|
||||
cout << "got = sign but no name" << endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pname[len] == '\0') {
|
||||
if (len) {
|
||||
cout << "no = sign before termminating null" << endl;
|
||||
}
|
||||
else {
|
||||
// empty property name -> free space reached
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!got_name) {
|
||||
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
|
||||
|
||||
this->data_length = pos; // point to after null
|
||||
}
|
||||
|
||||
//cout << "Read " << this->data_length << " bytes from nvram." << endl;
|
||||
return this->_config_vars;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::update_partition() {
|
||||
unsigned pos = 0;
|
||||
|
||||
memset(this->buf, 0, 4096);
|
||||
|
||||
for (auto& var : this->_config_vars) {
|
||||
if ((pos + 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]);
|
||||
}
|
||||
|
||||
//cout << "Wrote " << pos << " bytes to nvram." << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OfConfigChrp::set_var(std::string& var_name, std::string& value) {
|
||||
if (!this->validate())
|
||||
return false;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned free_space = 4096 - this->data_length;
|
||||
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;
|
||||
|
||||
if (value.length() > var.second.length()) {
|
||||
if ((value.length() - var.second.length()) > free_space) {
|
||||
cout << "No room for updated nvram variable!" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var.second = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
if ((var_name.length() + value.length() + 2) > free_space) {
|
||||
cout << "No room for new nvram variable!" << endl;
|
||||
return false;
|
||||
}
|
||||
this->_config_vars.push_back(std::make_pair(var_name, value));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static std::string ReplaceAll(std::string& str, const std::string& from, const std::string& to) {
|
||||
size_t start_pos = 0;
|
||||
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void OfConfigUtils::printenv() {
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
for (auto& var : vars) {
|
||||
std::string val = var.second;
|
||||
ReplaceAll(val, "\r\n", "\n");
|
||||
ReplaceAll(val, "\r", "\n");
|
||||
ReplaceAll(val, "\n", "\n "); // 34 spaces
|
||||
cout << setw(34) << left << var.first << val << endl; // name column has width 34
|
||||
}
|
||||
}
|
||||
|
||||
bool OfConfigUtils::setenv(string var_name, string value)
|
||||
{
|
||||
if (!this->open_container())
|
||||
return false;
|
||||
|
||||
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
return this->cfg_impl->set_var(var_name, 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/>.
|
||||
*/
|
||||
|
||||
/** Apple/CHRP Open Firmware NVRAM partition definitions. */
|
||||
|
||||
#ifndef OF_NVRAM_H
|
||||
#define OF_NVRAM_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class NVram;
|
||||
|
||||
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
|
||||
constexpr auto OF_NVRAM_OFFSET = 0x1800;
|
||||
constexpr auto OF_NVRAM_SIG = 0x1275;
|
||||
constexpr auto 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();
|
||||
bool 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,416 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** 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 <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;
|
||||
case BANDIT_DELAYED_AACK: // BANDIT_ONS
|
||||
return 0;
|
||||
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;
|
||||
case BANDIT_DELAYED_AACK:
|
||||
// implement this for CATALYST and Platinum
|
||||
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->get_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 >> 21) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
// I/O space
|
||||
return pci_io_read_broadcast(offset & 0x007FFFFF, size);
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
// CONFIG_ADDR
|
||||
return (this->is_aspen) ? this->config_addr : BYTESWAP_32(this->config_addr);
|
||||
|
||||
case 6:
|
||||
// CONFIG_DATA
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIBase *device;
|
||||
cfg_setup(offset, size, bus_num, dev_num, fun_num, reg_offs, details, device);
|
||||
details.flags |= PCI_CONFIG_READ;
|
||||
if (device) {
|
||||
uint32_t value = device->pci_cfg_read(reg_offs, details);
|
||||
// bytes 4 to 7 are random on bandit but
|
||||
// we choose to repeat bytes 0 to 3 like grackle
|
||||
return pci_conv_rd_data(value, value, details);
|
||||
}
|
||||
LOG_READ_NON_EXISTENT_PCI_DEVICE();
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
|
||||
case 7:
|
||||
// Interrupt
|
||||
LOG_F(ERROR, "%s: Interrupt Acknowledge Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
// 24-Bit Memory Address
|
||||
case 15:
|
||||
// 24-Bit Memory Address or VGA Device Access
|
||||
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset >> 21) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
// I/O space
|
||||
pci_io_write_broadcast(offset & 0x007FFFFF, size, value);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
// CONFIG_ADDR
|
||||
this->config_addr = (this->is_aspen) ? value : BYTESWAP_32(value);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
// CONFIG_DATA
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
AccessDetails details;
|
||||
PCIBase *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 7:
|
||||
// Special
|
||||
LOG_F(ERROR, "%s: Special Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
// 24-Bit Memory Address
|
||||
case 15:
|
||||
// 24-Bit Memory Address or VGA Device Access
|
||||
LOG_F(ERROR, "%s: Pass-Through read 0x%08x unsupported", this->name.c_str(), offset & 0x00FFFFFF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
int &dev_num, int &fun_num, uint8_t ®_offs,
|
||||
AccessDetails &details, PCIBase *&device)
|
||||
{
|
||||
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
|
||||
if (is_aspen)
|
||||
dev_num = (this->config_addr >> 11) + 11; // IDSEL = 1 << (dev_num + 11)
|
||||
else {
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
device = NULL;
|
||||
return;
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
}
|
||||
device = pci_find_device(dev_num, fun_num);
|
||||
}
|
||||
|
||||
int BanditHost::device_postinit() {
|
||||
return this->pcihost_device_postinit();
|
||||
}
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
: BanditHost(bridge_num)
|
||||
{
|
||||
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 + 0x00000000 --> I/O space
|
||||
// base_addr + 0x00800000 --> CONFIG_ADDR
|
||||
// base_addr + 0x00C00000 --> CONFIG_DATA
|
||||
// base_addr + 0x00E00000 --> Special(W)/Interrupt(R)
|
||||
// base_addr + 0x01000000 --> pass-through memory space ; grandcentral exists here for pci1
|
||||
mem_ctrl->add_mmio_region(base_addr, bridge_num == 1 ? 0x01000000 : 0x02000000, this);
|
||||
|
||||
// connnect Bandit PCI device
|
||||
this->my_pci_device = std::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(0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
AspenPci::AspenPci(std::string name) : BanditHost(1) {
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
this->is_aspen = true;
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Aspen PCI control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
mem_ctrl->add_mmio_region(0xF2000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
static const PropMap Bandit1_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap Bandit2_Properties = {
|
||||
{"pci_D2",
|
||||
new StrProperty("")},
|
||||
{"pci_E2",
|
||||
new StrProperty("")},
|
||||
{"pci_F2",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap Chaos_Properties = {
|
||||
{"vci_D",
|
||||
new StrProperty("")},
|
||||
{"vci_E",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const PropMap PsxPci1_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
{"pci_E1",
|
||||
new StrProperty("")},
|
||||
{"pci_F1",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
Bandit::create_first, {}, Bandit1_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit2_Descriptor = {
|
||||
Bandit::create_second, {}, Bandit2_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, PsxPci1_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, {}, Chaos_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription AspenPci1_Descriptor = {
|
||||
AspenPci::create, {}, Bandit1_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(AspenPci1, AspenPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
constexpr auto BANDIT_DEV = 11; // Bandit's own device number
|
||||
constexpr auto 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,
|
||||
BANDIT_DELAYED_AACK = 0x60,
|
||||
};
|
||||
|
||||
/** 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:
|
||||
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) override;
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) override;
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
protected:
|
||||
uint32_t config_addr;
|
||||
int bridge_num;
|
||||
bool is_aspen = false;
|
||||
|
||||
private:
|
||||
void cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num,
|
||||
int &fun_num, uint8_t ®_offs, AccessDetails &details,
|
||||
PCIBase *&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_second() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(2, "Bandit-PCI2"));
|
||||
};
|
||||
|
||||
static std::unique_ptr<HWComponent> create_psx_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "PSX-PCI1", 8, 0));
|
||||
};
|
||||
|
||||
private:
|
||||
std::unique_ptr<BanditPciDevice> my_pci_device;
|
||||
uint32_t base_addr;
|
||||
};
|
||||
|
||||
/**
|
||||
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"));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
Aspen PCI Bridge HLE emulation class.
|
||||
*/
|
||||
class AspenPci : public BanditHost {
|
||||
public:
|
||||
AspenPci(std::string name);
|
||||
~AspenPci() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
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 <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 PropMap Dec21154Yosemite_Properties = {
|
||||
{"pci_FireWire",
|
||||
new StrProperty("")},
|
||||
{"pci_UltraATA",
|
||||
new StrProperty("")},
|
||||
{"pci_J11",
|
||||
new StrProperty("")},
|
||||
{"pci_J10",
|
||||
new StrProperty("")},
|
||||
{"pci_J9",
|
||||
new StrProperty("")},
|
||||
{"pci_USB",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Dec21154_Descriptor = {
|
||||
DecPciBridge::create, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Dec21154Yosemite_Descriptor = {
|
||||
DecPciBridge::create_yosemite, {}, Dec21154Yosemite_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Dec21154, Dec21154_Descriptor);
|
||||
REGISTER_DEVICE(Dec21154Yosemite, Dec21154Yosemite_Descriptor);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_yosemite() {
|
||||
return std::unique_ptr<DecPciBridge>(new DecPciBridge("DEC21154Yosemite"));
|
||||
}
|
||||
|
||||
// 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,323 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcibase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
|
||||
{
|
||||
this->name = name;
|
||||
this->hdr_type = hdr_type;
|
||||
this->num_bars = num_bars;
|
||||
|
||||
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) {
|
||||
/*
|
||||
FIXME: should register or unregister BAR mmio regions if (cmd & 2) changes.
|
||||
Or the mmio regions should be enabled/disabled.
|
||||
*/
|
||||
this->command = cmd & this->command_cfg;
|
||||
};
|
||||
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 PCIBase::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();
|
||||
}
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PCIBase::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;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBase::setup_bars(std::vector<BarConfig> cfg_data)
|
||||
{
|
||||
for (auto cfg_entry : cfg_data) {
|
||||
if (cfg_entry.bar_num > this->num_bars) {
|
||||
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 PCIBase::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->get_name().c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
|
||||
this->get_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, "%s: %s", this->get_name().c_str(), exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
img_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PCIBase::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);
|
||||
if (value != 0xFFFFFFFFUL && (value & ~3) != (value & bar_cfg & ~3)) {
|
||||
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
|
||||
this->get_name().c_str(), bar_num, (value & ~3), (value & 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);
|
||||
if (value != 0xFFFFFFFFUL && (value & ~0xF) != (value & bar_cfg & ~0xF)) {
|
||||
LOG_F(ERROR, "%s: BAR %d cannot be 0x%08x (set to 0x%08x)",
|
||||
this->get_name().c_str(), bar_num, (value & ~0xF), (value & 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 PCIBase::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->get_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->get_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->get_name().c_str(), pci_space_type, bar_num);
|
||||
} // switch pci_space_type
|
||||
}
|
||||
} // for bar_num
|
||||
}
|
||||
|
||||
void PCIBase::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 PCIBase::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 PCIBase::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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBase::pci_interrupt(uint8_t irq_line_state) {
|
||||
if (!(this->command & 0x0400)) {
|
||||
if (!this->int_details.int_ctrl_obj)
|
||||
this->host_instance->register_pci_int(this);
|
||||
if (this->int_details.int_ctrl_obj && this->int_details.irq_id)
|
||||
this->int_details.int_ctrl_obj->ack_int(this->int_details.irq_id, irq_line_state);
|
||||
else
|
||||
LOG_F(ERROR, "Unhandled interrupt from device %s", this->get_name().c_str());
|
||||
/* A pci device should set the interrupt status bit when an interrupt occurs
|
||||
* and it should clear the interrupt status bit when its interrupt bits are cleared.
|
||||
* The interrupt status bit is new to PCI Local Bus Specification Revision 2.3
|
||||
* and Power Macs use PCI Local Bus Specification Revision 2.0. Some PCI cards
|
||||
* might not implement this bit.
|
||||
*/
|
||||
//this->status |= 0x0008;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PCI_BASE_H
|
||||
#define PCI_BASE_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 header types */
|
||||
enum PCIHeaderType : uint8_t {
|
||||
PCI_HEADER_TYPE_0 = 0, // PCI Device
|
||||
PCI_HEADER_TYPE_1 = 1, // PCI-PCI Bridge
|
||||
PCI_HEADER_TYPE_2 = 2, // PCI-To-Cardbus Bridge
|
||||
};
|
||||
|
||||
/** 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 (type 0, 1, and 2)
|
||||
PCI_CFG_BAR1 = 0x14, // base address register 1 (type 0 and 1)
|
||||
PCI_CFG_DWORD_13 = 0x34, // capabilities pointer (type 0 and 1)
|
||||
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt (Type 0)
|
||||
// Bridge Control (Type 1 and 2)
|
||||
// Int_Pin and Int_Line registers (type 0, 1, and 2)
|
||||
};
|
||||
|
||||
/** 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_SILICON_IMAGE = 0x1095,
|
||||
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 PCIBase : public MMIODevice {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars);
|
||||
virtual ~PCIBase() = 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;
|
||||
}
|
||||
|
||||
virtual void set_int_details(IntDetails &int_details) {
|
||||
this->int_details = int_details;
|
||||
}
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state);
|
||||
|
||||
// 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();
|
||||
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
|
||||
// PCI configuration space state (type 0, 1, and 2)
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint16_t command = 0;
|
||||
uint16_t status = 0;
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t hdr_type; // header type, single function
|
||||
uint8_t cap_ptr = 0; // capabilities ptr
|
||||
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
bool has_io_space = false;
|
||||
int num_bars; // number of BARs. Type 0:6, type 1:2, type 2:1 (4K)
|
||||
uint32_t bars[6] = { 0 }; // BARs (base address registers)
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for BARs
|
||||
PCIBarType bars_typ[6] = { PCIBarType::Unused }; // types for BARs
|
||||
|
||||
// PCI configuration space state (type 0 and 1)
|
||||
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;
|
||||
|
||||
// 0 = not writable; 1 = bit is enabled in command register
|
||||
uint16_t command_cfg = 0xffff - (1<<3) - (1<<7); // disable: special cycles and stepping
|
||||
|
||||
IntDetails int_details = { 0 };
|
||||
};
|
||||
|
||||
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 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_ARG(details.size) \
|
||||
); \
|
||||
} } 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_ARG(details.size), \
|
||||
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_ARG(details.size) \
|
||||
)
|
||||
|
||||
#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_ARG(details.size), \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
)
|
||||
|
||||
#endif /* PCI_BASE_H */
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
PCIBridge::PCIBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_1, 2)
|
||||
{
|
||||
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_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;
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t PCIBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
return this->bars[(reg_offs - 0x10) >> 2];
|
||||
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_DWORD_13:
|
||||
return cap_ptr;
|
||||
case PCI_CFG_BRIDGE_ROM_ADDRESS:
|
||||
return exp_rom_bar;
|
||||
default:
|
||||
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, value);
|
||||
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;
|
||||
default:
|
||||
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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_write_loop(offset, size, value);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PCI_BRIDGE_H
|
||||
#define PCI_BRIDGE_H
|
||||
|
||||
#include <devices/common/pci/pcibridgebase.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
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_BRIDGE_ROM_ADDRESS = 0x38, // BRIDGE_ROM_ADDRESS
|
||||
};
|
||||
|
||||
class PCIBridge : public PCIBridgeBase {
|
||||
public:
|
||||
PCIBridge(std::string name);
|
||||
~PCIBridge() = default;
|
||||
|
||||
// PCIBase 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);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
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;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
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;
|
||||
|
||||
// 0 = not writable, 0xf0 = supports 16 bit I/O 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;
|
||||
|
||||
// calculated address ranges
|
||||
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;
|
||||
};
|
||||
|
||||
#endif /* PCI_BRIDGE_H */
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
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/pcibridgebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_bars) : PCIBase(name, hdr_type, num_bars)
|
||||
{
|
||||
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_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_bridge_control = [this](uint16_t val) { this->bridge_control = val; };
|
||||
};
|
||||
|
||||
bool PCIBridgeBase::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
// FIXME: constrain region to memory range
|
||||
return this->host_instance->pci_register_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
bool PCIBridgeBase::pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
return this->host_instance->pci_unregister_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
uint32_t PCIBridgeBase::pci_cfg_read(uint32_t reg_offs, AccessDetails &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_DWORD_15:
|
||||
return (this->pci_rd_bridge_control() << 16) | (irq_pin << 8) | irq_line;
|
||||
default:
|
||||
return PCIBase::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
}
|
||||
|
||||
void PCIBridgeBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &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_DWORD_15:
|
||||
this->irq_line = value >> 24;
|
||||
this->pci_wr_bridge_control(value >> 16);
|
||||
break;
|
||||
default:
|
||||
return PCIBase::pci_cfg_write(reg_offs, value, details);
|
||||
}
|
||||
}
|
||||
|
||||
int PCIBridgeBase::device_postinit() {
|
||||
return this->pcihost_device_postinit();
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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_BASE_H
|
||||
#define PCI_BRIDGE_BASE_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcibase.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets (type 1 and 2) */
|
||||
enum {
|
||||
PCI_CFG_PRIMARY_BUS = 0x18, // PRIMARY_BUS, SECONDARY_BUS, SUBORDINATE_BUS, SEC_LATENCY_TIMER
|
||||
};
|
||||
|
||||
class PCIBridgeBase : public PCIHost, public PCIBase {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_bars);
|
||||
~PCIBridgeBase() = default;
|
||||
|
||||
// PCIHost methods
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
|
||||
// PCIBase 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);
|
||||
|
||||
bool supports_io_space() {
|
||||
return true;
|
||||
};
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
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<uint16_t()> pci_rd_bridge_control;
|
||||
std::function<void(uint16_t)> pci_wr_bridge_control;
|
||||
|
||||
// HWComponent methods
|
||||
virtual int device_postinit();
|
||||
|
||||
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;
|
||||
uint16_t bridge_control = 0;
|
||||
|
||||
// 0 = not writable, 0xf8 = limits the granularity to eight PCI clocks
|
||||
uint8_t sec_latency_timer_cfg = 0xff;
|
||||
};
|
||||
|
||||
#endif /* PCI_BRIDGE_BASE_H */
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
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/pcicardbusbridge.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
typedef struct {
|
||||
// CardBus Registers
|
||||
/* 0x00 */ uint32_t Event;
|
||||
/* 0x04 */ uint32_t Mask;
|
||||
/* 0x08 */ uint32_t PresentState;
|
||||
/* 0x0C */ uint32_t Force;
|
||||
/* 0x10 */ uint32_t Control;
|
||||
/* 0x14 */ uint32_t Reserved[4];
|
||||
/* 0x20 */ uint32_t UserDefined20h[504];
|
||||
|
||||
// 16-Bit Registers
|
||||
/* 0x800 */ uint8_t IDAndRevision;
|
||||
/* 0x801 */ uint8_t IFStatus;
|
||||
/* 0x802 */ uint8_t PowerAndResetDrvControl;
|
||||
/* 0x803 */ uint8_t InterruptAndGeneralControl;
|
||||
/* 0x804 */ uint8_t CardStatusChange;
|
||||
/* 0x805 */ uint8_t CardStatusChangeInterruptConfiguration;
|
||||
/* 0x806 */ uint8_t AddressWindowEnable;
|
||||
/* 0x807 */ uint8_t IOControl;
|
||||
/* 0x808 */ uint16_t IOAdd0Start;
|
||||
/* 0x80A */ uint16_t IOAdd0Stop;
|
||||
/* 0x80C */ uint16_t IOAdd1Start;
|
||||
/* 0x80E */ uint16_t IOAdd1Stop;
|
||||
/* 0x810 */ uint16_t SysMemAdd0Start;
|
||||
/* 0x812 */ uint16_t SysMemAdd0Stop;
|
||||
/* 0x814 */ uint16_t CardMemoryOffsetAdd0;
|
||||
/* 0x816 */ uint16_t UserDefined814h;
|
||||
/* 0x818 */ uint16_t SysMemAdd1Start;
|
||||
/* 0x81A */ uint16_t SysMemAdd1Stop;
|
||||
/* 0x81C */ uint16_t CardMemoryOffsetAdd1;
|
||||
/* 0x81E */ uint16_t UserDefined81Ch;
|
||||
/* 0x820 */ uint16_t SysMemAdd2Start;
|
||||
/* 0x822 */ uint16_t SysMemAdd2Stop;
|
||||
/* 0x824 */ uint16_t CardMemoryOffsetAdd2;
|
||||
/* 0x826 */ uint16_t UserDefined824h;
|
||||
/* 0x828 */ uint16_t SysMemAdd3Start;
|
||||
/* 0x82A */ uint16_t SysMemAdd3Stop;
|
||||
/* 0x82C */ uint16_t CardMemoryOffsetAdd3;
|
||||
/* 0x82E */ uint16_t UserDefined82Ch;
|
||||
/* 0x830 */ uint16_t SysMemAdd4Start;
|
||||
/* 0x832 */ uint16_t SysMemAdd4Stop;
|
||||
/* 0x834 */ uint16_t CardMemoryOffsetAdd4;
|
||||
/* 0x836 */ uint16_t UserDefined834h;
|
||||
/* 0x838 */ uint32_t UserDefined838h[4];
|
||||
/* 0x840 */ uint8_t SysMemAdd0MappingStartUp;
|
||||
/* 0x841 */ uint8_t SysMemAdd1MappingStartUp;
|
||||
/* 0x842 */ uint8_t SysMemAdd2MappingStartUp;
|
||||
/* 0x843 */ uint8_t SysMemAdd3MappingStartUp;
|
||||
/* 0x844 */ uint8_t SysMemAdd4MappingStartUp;
|
||||
/* 0x845 */ uint8_t UserDefined845h;
|
||||
/* 0x846 */ uint16_t UserDefined846h;
|
||||
/* 0x848 */ uint32_t UserDefined848h[494];
|
||||
} CardBusStatusAnfControlRegisters;
|
||||
|
||||
PCICardbusBridge::PCICardbusBridge(std::string name) : PCIBridgeBase(name, PCI_HEADER_TYPE_2, 1)
|
||||
{
|
||||
this->pci_rd_memory_base_0 = [this]() { return this->memory_base_0 ; };
|
||||
this->pci_rd_memory_limit_0 = [this]() { return this->memory_limit_0 ; };
|
||||
this->pci_rd_memory_base_1 = [this]() { return this->memory_base_1 ; };
|
||||
this->pci_rd_memory_limit_1 = [this]() { return this->memory_limit_1 ; };
|
||||
this->pci_rd_io_base_0 = [this]() { return this->io_base_0 ; };
|
||||
this->pci_rd_io_limit_0 = [this]() { return this->io_limit_0 ; };
|
||||
this->pci_rd_io_base_1 = [this]() { return this->io_base_1 ; };
|
||||
this->pci_rd_io_limit_1 = [this]() { return this->io_limit_1 ; };
|
||||
|
||||
this->pci_wr_memory_base_0 = [this](uint32_t val) {
|
||||
this->memory_base_0 = val & this->memory_0_cfg;
|
||||
this->memory_base_0_32 = this->memory_base_0;
|
||||
};
|
||||
|
||||
this->pci_wr_memory_limit_0 = [this](uint32_t val) {
|
||||
this->memory_limit_0 = val & this->memory_0_cfg;
|
||||
this->memory_limit_0_32 = this->memory_limit_0 + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_memory_base_1 = [this](uint32_t val) {
|
||||
this->memory_base_1 = val & this->memory_1_cfg;
|
||||
this->memory_base_1_32 = this->memory_base_1;
|
||||
};
|
||||
|
||||
this->pci_wr_memory_limit_1 = [this](uint32_t val) {
|
||||
this->memory_limit_1 = val & this->memory_1_cfg;
|
||||
this->memory_limit_1_32 = this->memory_limit_1 + 0x1000;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base_0 = [this](uint32_t val) {
|
||||
this->io_base_0 = (val & this->io_0_cfg) | (io_0_cfg & 3);
|
||||
this->io_base_0_32 = (this->io_base_0 & ~3);
|
||||
};
|
||||
|
||||
this->pci_wr_io_limit_0 = [this](uint32_t val) {
|
||||
this->io_limit_0 = (val & this->io_0_cfg);
|
||||
this->io_limit_0_32 = this->io_limit_0 + 4;
|
||||
};
|
||||
|
||||
this->pci_wr_io_base_1 = [this](uint32_t val) {
|
||||
this->io_base_1 = (val & this->io_1_cfg) | (io_1_cfg & 3);
|
||||
this->io_base_1_32 = (this->io_base_1 & ~3);
|
||||
};
|
||||
|
||||
this->pci_wr_io_limit_1 = [this](uint32_t val) {
|
||||
this->io_limit_1 = (val & this->io_1_cfg);
|
||||
this->io_limit_1_32 = this->io_limit_1 + 4;
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t PCICardbusBridge::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
return this->bars[(reg_offs - 0x10) >> 2];
|
||||
case PCI_CFG_CB_CAPABILITIES:
|
||||
return (this->pci_rd_sec_status() << 16) | cap_ptr;
|
||||
case PCI_CFG_CB_MEMORY_BASE_0:
|
||||
return this->pci_rd_memory_base_0();
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_0:
|
||||
return this->pci_rd_memory_limit_0();
|
||||
case PCI_CFG_CB_MEMORY_BASE_1:
|
||||
return this->pci_rd_memory_base_0();
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_1:
|
||||
return this->pci_rd_memory_limit_0();
|
||||
case PCI_CFG_CB_IO_BASE_0:
|
||||
return this->pci_rd_io_base_0();
|
||||
case PCI_CFG_CB_IO_LIMIT_0:
|
||||
return this->pci_rd_io_limit_0();
|
||||
case PCI_CFG_CB_IO_BASE_1:
|
||||
return this->pci_rd_io_base_0();
|
||||
case PCI_CFG_CB_IO_LIMIT_1:
|
||||
return this->pci_rd_io_limit_0();
|
||||
case PCI_CFG_CB_SUBSYSTEM_IDS:
|
||||
return (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
case PCI_CFG_CB_LEGACY_MODE_BASE:
|
||||
return this->legacy_mode_base;
|
||||
default:
|
||||
return PCIBridgeBase::pci_cfg_read(reg_offs, details);
|
||||
}
|
||||
}
|
||||
|
||||
void PCICardbusBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
||||
{
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_BAR0:
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, value);
|
||||
break;
|
||||
case PCI_CFG_CB_CAPABILITIES:
|
||||
this->pci_wr_sec_status(value >> 16);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_BASE_0:
|
||||
this->pci_wr_memory_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_0:
|
||||
this->pci_wr_memory_limit_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_BASE_1:
|
||||
this->pci_wr_memory_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_MEMORY_LIMIT_1:
|
||||
this->pci_wr_memory_limit_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_BASE_0:
|
||||
this->pci_wr_io_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_LIMIT_0:
|
||||
this->pci_wr_io_limit_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_BASE_1:
|
||||
this->pci_wr_io_base_0(value);
|
||||
break;
|
||||
case PCI_CFG_CB_IO_LIMIT_1:
|
||||
this->pci_wr_io_limit_0(value);
|
||||
break;
|
||||
/*
|
||||
case PCI_CFG_CB_LEGACY_MODE_BASE:
|
||||
this->legacy_mode_base = value;
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
PCIBridgeBase::pci_cfg_write(reg_offs, value, details);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool PCICardbusBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
|
||||
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
|
||||
) return false;
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCICardbusBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if ((offset < this->io_base_0_32 || offset + size >= this->io_limit_0_32) &&
|
||||
(offset < this->io_base_1_32 || offset + size >= this->io_limit_1_32)
|
||||
) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
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_CARDBUSBRIDGE_H
|
||||
#define PCI_CARDBUSBRIDGE_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/pci/pcibridgebase.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
PCI_CFG_CB_CAPABILITIES = 0x14, // CB_CAPABILITIES.b, 0.b, CB_SEC_STATUS.w
|
||||
PCI_CFG_CB_MEMORY_BASE_0 = 0x1C,
|
||||
PCI_CFG_CB_MEMORY_LIMIT_0 = 0x20,
|
||||
PCI_CFG_CB_MEMORY_BASE_1 = 0x24,
|
||||
PCI_CFG_CB_MEMORY_LIMIT_1 = 0x28,
|
||||
PCI_CFG_CB_IO_BASE_0 = 0x2C,
|
||||
PCI_CFG_CB_IO_LIMIT_0 = 0x30,
|
||||
PCI_CFG_CB_IO_BASE_1 = 0x34,
|
||||
PCI_CFG_CB_IO_LIMIT_1 = 0x38,
|
||||
PCI_CFG_CB_SUBSYSTEM_IDS = 0x40, // CB_SUBSYSTEM_VENDOR_ID.w, CB_SUBSYSTEM_ID.w
|
||||
PCI_CFG_CB_LEGACY_MODE_BASE = 0x44,
|
||||
};
|
||||
|
||||
class PCICardbusBridge : public PCIBridgeBase {
|
||||
public:
|
||||
PCICardbusBridge(std::string name);
|
||||
~PCICardbusBridge() = default;
|
||||
|
||||
// PCIBase 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);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint32_t()> pci_rd_memory_base_0;
|
||||
std::function<void(uint32_t)> pci_wr_memory_base_0;
|
||||
std::function<uint32_t()> pci_rd_memory_limit_0;
|
||||
std::function<void(uint32_t)> pci_wr_memory_limit_0;
|
||||
std::function<uint32_t()> pci_rd_memory_base_1;
|
||||
std::function<void(uint32_t)> pci_wr_memory_base_1;
|
||||
std::function<uint32_t()> pci_rd_memory_limit_1;
|
||||
std::function<void(uint32_t)> pci_wr_memory_limit_1;
|
||||
std::function<uint32_t()> pci_rd_io_base_0;
|
||||
std::function<void(uint32_t)> pci_wr_io_base_0;
|
||||
std::function<uint32_t()> pci_rd_io_limit_0;
|
||||
std::function<void(uint32_t)> pci_wr_io_limit_0;
|
||||
std::function<uint32_t()> pci_rd_io_base_1;
|
||||
std::function<void(uint32_t)> pci_wr_io_base_1;
|
||||
std::function<uint32_t()> pci_rd_io_limit_1;
|
||||
std::function<void(uint32_t)> pci_wr_io_limit_1;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint32_t memory_base_0 = 0;
|
||||
uint32_t memory_limit_0 = 0;
|
||||
uint32_t memory_base_1 = 0;
|
||||
uint32_t memory_limit_1 = 0;
|
||||
uint32_t io_base_0 = 0;
|
||||
uint32_t io_limit_0 = 0;
|
||||
uint32_t io_base_1 = 0;
|
||||
uint32_t io_limit_1 = 0;
|
||||
uint16_t subsys_id = 0;
|
||||
uint16_t subsys_vndr = 0;
|
||||
uint32_t legacy_mode_base = 0;
|
||||
|
||||
// 0 = not writable
|
||||
uint32_t memory_0_cfg = 0xfffff000;
|
||||
uint32_t memory_1_cfg = 0xfffff000;
|
||||
|
||||
// 0 = not writable, 0x0000fffc = supports 16 bit I/O range, 0xfffffffd = supports 32 bit I/O range
|
||||
uint32_t io_0_cfg = 0x0000fffc;
|
||||
uint32_t io_1_cfg = 0x0000fffc;
|
||||
|
||||
// calculated address ranges
|
||||
uint32_t memory_base_0_32 = 0;
|
||||
uint32_t memory_limit_0_32 = 0;
|
||||
uint32_t memory_base_1_32 = 0;
|
||||
uint32_t memory_limit_1_32 = 0;
|
||||
uint32_t io_base_0_32 = 0;
|
||||
uint32_t io_limit_0_32 = 0;
|
||||
uint32_t io_base_1_32 = 0;
|
||||
uint32_t io_limit_1_32 = 0;
|
||||
};
|
||||
|
||||
#endif /* PCI_CARDBUSBRIDGE_H */
|
||||
Loaded 100 of 443 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user