mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
732
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af055e0519 | ||
|
|
f2f048d435 | ||
|
|
a62a1dcd09 | ||
|
|
74da4e148d | ||
|
|
c0cd18323e | ||
|
|
b848ea2300 | ||
|
|
f9f77f78a8 | ||
|
|
f7b88cf5ee | ||
|
|
72dbafdb3f | ||
|
|
f55d5c9002 | ||
|
|
65d414bd4e | ||
|
|
fa5e8b0bf8 | ||
|
|
b05dec8778 | ||
|
|
24a18f7769 | ||
|
|
a74ad4b1d1 | ||
|
|
6c430b7d83 | ||
|
|
2ce4e13170 | ||
|
|
746f461c5b | ||
|
|
00be8ce606 | ||
|
|
a1f15228fd | ||
|
|
16762ab9e3 | ||
|
|
28c497e455 | ||
|
|
5b3043c372 | ||
|
|
0019681be4 | ||
|
|
c1ed416b58 | ||
|
|
72ef266d07 | ||
|
|
c781ba8fab | ||
|
|
c6013f076a | ||
|
|
9c6a7de45f | ||
|
|
47c66666bb | ||
|
|
534d092bd5 | ||
|
|
4d0904667c | ||
|
|
e82d9d1522 | ||
|
|
e64cf73543 | ||
|
|
88b5b2ec66 | ||
|
|
1340fbedb8 | ||
|
|
36c7c807a4 | ||
|
|
61a8402f84 | ||
|
|
d315624d54 | ||
|
|
ec6fa9360c | ||
|
|
0fe6ffeb6f | ||
|
|
2f8e8bf68b | ||
|
|
a5e2adefa9 | ||
|
|
16542a09f5 | ||
|
|
fa865a79fc | ||
|
|
fa7fb5bb1f | ||
|
|
0899d84019 | ||
|
|
3e88c161c1 | ||
|
|
2253e6c595 | ||
|
|
86a09a9d3c | ||
|
|
71990129f3 | ||
|
|
ab8abf39cc | ||
|
|
8c84b78804 | ||
|
|
4312450b70 | ||
|
|
a75d806108 | ||
|
|
2a830154f9 | ||
|
|
89d5196e8b | ||
|
|
842d0f7f70 | ||
|
|
23ea02b47c | ||
|
|
5bd1071d10 | ||
|
|
be59ed8304 | ||
|
|
e4dedb8c09 | ||
|
|
17f2562d13 | ||
|
|
6adce6b120 | ||
|
|
aec5aba379 | ||
|
|
f40ce18bc5 | ||
|
|
e4f0588b56 | ||
|
|
7ab54276ad | ||
|
|
630755f9e5 | ||
|
|
0efab12699 | ||
|
|
b280da81bc | ||
|
|
6363eef32f | ||
|
|
2b4962d1ba | ||
|
|
d66c2a39a3 | ||
|
|
fe304d9f46 | ||
|
|
081e0f0576 | ||
|
|
a628d8aa5d | ||
|
|
b2bff25cc2 | ||
|
|
3940080f78 | ||
|
|
28c50a2018 | ||
|
|
3e3eee7ae9 | ||
|
|
41aa8b73e9 | ||
|
|
556d00116f | ||
|
|
f4d40ae26b | ||
|
|
ca55defc55 | ||
|
|
43f5b56033 | ||
|
|
8484e52407 | ||
|
|
1565d21176 | ||
|
|
986fc22fd4 | ||
|
|
1046baf11d | ||
|
|
c4906d1f15 | ||
|
|
a5dc3bceb9 | ||
|
|
3bab9b6f52 | ||
|
|
25beb13b1b | ||
|
|
99c06e8690 | ||
|
|
c483a9a615 | ||
|
|
4b25da926b | ||
|
|
06a9e338a9 | ||
|
|
26db2caadd | ||
|
|
ff6d75f232 | ||
|
|
f6f11e81e9 | ||
|
|
c742beb623 | ||
|
|
ba030abb3b | ||
|
|
df5c1758d5 | ||
|
|
b5edd8347e | ||
|
|
ed433c0476 | ||
|
|
fb03c214ae | ||
|
|
503c6ea662 | ||
|
|
2d61e4c604 | ||
|
|
03bb03fdd5 | ||
|
|
c10183b58f | ||
|
|
be1b567b84 | ||
|
|
237f983493 | ||
|
|
2a3e46eab4 | ||
|
|
d4d19e880c | ||
|
|
1166fda3e0 | ||
|
|
8b1d673e10 | ||
|
|
4ac5fd4cb0 | ||
|
|
6da691fb02 | ||
|
|
8f64d35210 | ||
|
|
61d73a5b79 | ||
|
|
794a345e53 | ||
|
|
1c54cdd368 | ||
|
|
026d53f275 | ||
|
|
ca20de9462 | ||
|
|
7893d0add7 | ||
|
|
7f34504259 | ||
|
|
48fd95e284 | ||
|
|
15baf9a2a0 | ||
|
|
a0edc825fb | ||
|
|
20e7dfb0e1 | ||
|
|
83066bbf5f | ||
|
|
637c20e3cf | ||
|
|
ba9bbb32c3 | ||
|
|
60c95231ee | ||
|
|
130beabf2a | ||
|
|
a7170f4956 | ||
|
|
10f087be65 | ||
|
|
392f6cdcd3 | ||
|
|
e43bb02d9a | ||
|
|
341d5470a2 | ||
|
|
2b0c932e48 | ||
|
|
35095870b2 | ||
|
|
a178d12a80 | ||
|
|
43361815d2 | ||
|
|
ddb3657d89 | ||
|
|
8ce9abcf22 | ||
|
|
aee50331e9 | ||
|
|
f784cedc0b | ||
|
|
d300a31fa7 | ||
|
|
9874aa1dfc | ||
|
|
08f67c010c | ||
|
|
c3005cede3 | ||
|
|
cf0d78fe98 | ||
|
|
8aede43f91 | ||
|
|
a7386a648e | ||
|
|
69c4d6489d | ||
|
|
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 |
No files matched your search
+231
-9
@@ -1,43 +1,265 @@
|
||||
name: CMake
|
||||
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
|
||||
# You can convert this to a matrix build if you need cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: install_dependencies
|
||||
run: |
|
||||
sudo apt-get update -y -qq
|
||||
sudo apt-get install libsdl2-dev
|
||||
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Configure CMake
|
||||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
|
||||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
|
||||
|
||||
- name: Build
|
||||
# Build your program with the given configuration
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-LINUX
|
||||
path: ${{github.workspace}}/build/bin
|
||||
- name: Test
|
||||
working-directory: ${{github.workspace}}/build
|
||||
# Execute tests defined by the CMake configuration.
|
||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
||||
run: ctest -C ${{env.BUILD_TYPE}}
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
cache-name: [msys64-cache]
|
||||
env:
|
||||
MSYSTEM: MINGW64
|
||||
FF_SCRIPT_SECTIONS: '0'
|
||||
CONFIGURE_ARGS: '--target-list=x86_64-softmmu --without-default-devices -Ddebug=false -Doptimization=0'
|
||||
TEST_ARGS: '--no-suite qtest'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up MSYS2
|
||||
run: |
|
||||
Write-Output "Acquiring msys2.exe installer at $(Get-Date -Format u)"
|
||||
If ( !(Test-Path -Path msys64\var\cache ) ) {
|
||||
mkdir msys64\var\cache
|
||||
}
|
||||
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe.sig" -outfile "msys2.exe.sig"
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe.sig ) {
|
||||
Write-Output "Cached installer sig" ;
|
||||
if ( ((Get-FileHash msys2.exe.sig).Hash -ne (Get-FileHash msys64\var\cache\msys2.exe.sig).Hash) ) {
|
||||
Write-Output "Mis-matched installer sig, new installer download required" ;
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe.sig ;
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe
|
||||
}
|
||||
} else {
|
||||
Write-Output "Matched installer sig, cached installer still valid"
|
||||
}
|
||||
} else {
|
||||
Write-Output "No cached installer sig, new installer download required" ;
|
||||
if ( Test-Path -Path msys64\var\cache\msys2.exe ) {
|
||||
Remove-Item -Path msys64\var\cache\msys2.exe
|
||||
}
|
||||
}
|
||||
if ( !(Test-Path -Path msys64\var\cache\msys2.exe ) ) {
|
||||
Write-Output "Fetching latest installer" ;
|
||||
Invoke-WebRequest "https://repo.msys2.org/distrib/msys2-x86_64-latest.sfx.exe" -outfile "msys64\var\cache\msys2.exe" ;
|
||||
Copy-Item -Path msys2.exe.sig -Destination msys64\var\cache\msys2.exe.sig
|
||||
} else {
|
||||
Write-Output "Using cached installer"
|
||||
}
|
||||
Write-Output "Invoking msys2.exe installer at $(Get-Date -Format u)"
|
||||
msys64\var\cache\msys2.exe -y
|
||||
((Get-Content -path .\msys64\etc\post-install\07-pacman-key.post -Raw) -replace '--refresh-keys', '--version') | Set-Content -Path .\msys64\etc\post-install\07-pacman-key.post
|
||||
.\msys64\usr\bin\bash -lc "sed -i 's/^CheckSpace/#CheckSpace/g' /etc/pacman.conf"
|
||||
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Core update
|
||||
.\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syuu' # Normal update
|
||||
taskkill /F /FI "MODULES eq msys-2.0.dll"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
Write-Output "Installing mingw packages at $(Get-Date -Format u)"
|
||||
.\msys64\usr\bin\bash -lc 'pacman -Sy --noconfirm --needed \
|
||||
bison \
|
||||
diffutils \
|
||||
flex \
|
||||
tar \
|
||||
doxygen \
|
||||
cmake \
|
||||
wget \
|
||||
git \
|
||||
grep \
|
||||
make \
|
||||
rsync \
|
||||
ninja \
|
||||
glib2-devel \
|
||||
patch \
|
||||
sed \
|
||||
mingw-w64-x86_64-cmake \
|
||||
mingw-w64-x86_64-binutils \
|
||||
mingw-w64-x86_64-doxygen \
|
||||
mingw-w64-x86_64-capstone \
|
||||
mingw-w64-x86_64-ccache \
|
||||
mingw-w64-x86_64-curl \
|
||||
mingw-w64-x86_64-cyrus-sasl \
|
||||
mingw-w64-x86_64-dtc \
|
||||
mingw-w64-x86_64-gcc \
|
||||
mingw-w64-x86_64-glib2 \
|
||||
mingw-w64-x86_64-gnutls \
|
||||
mingw-w64-x86_64-gtk3 \
|
||||
mingw-w64-x86_64-libgcrypt \
|
||||
mingw-w64-x86_64-libjpeg-turbo \
|
||||
mingw-w64-x86_64-libnfs \
|
||||
mingw-w64-x86_64-libpng \
|
||||
mingw-w64-x86_64-libssh \
|
||||
mingw-w64-x86_64-libtasn1 \
|
||||
mingw-w64-x86_64-libusb \
|
||||
mingw-w64-x86_64-lzo2 \
|
||||
mingw-w64-x86_64-libslirp \
|
||||
mingw-w64-x86_64-nettle \
|
||||
mingw-w64-x86_64-clang \
|
||||
mingw-w64-x86_64-ninja \
|
||||
mingw-w64-x86_64-pixman \
|
||||
mingw-w64-x86_64-pkgconf \
|
||||
mingw-w64-x86_64-python \
|
||||
mingw-w64-x86_64-SDL2 \
|
||||
mingw-w64-x86_64-SDL2_image \
|
||||
mingw-w64-x86_64-snappy \
|
||||
mingw-w64-x86_64-spice \
|
||||
mingw-w64-x86_64-usbredir \
|
||||
mingw-w64-x86_64-zstd \
|
||||
mingw-w64-x86_64-make'
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
run: |
|
||||
Write-Output "Running build at $(Get-Date -Format u)"
|
||||
$env:CHERE_INVOKING = 'yes' # Preserve the current working directory
|
||||
$env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
|
||||
$env:CCACHE_BASEDIR = "$env:CI_PROJECT_DIR"
|
||||
$env:CCACHE_DIR = "$env:CCACHE_BASEDIR/ccache"
|
||||
$env:CCACHE_MAXSIZE = "500M"
|
||||
$env:CCACHE_DEPEND = 1 # cache misses are too expensive with preprocessor mode
|
||||
$env:CC = "ccache gcc"
|
||||
mkdir build
|
||||
cd build
|
||||
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --zero-stats"
|
||||
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True .. && ninja"
|
||||
D:\a\dingusppc\dingusppc\msys64\usr\bin\bash -lc "ccache --show-stats"
|
||||
Write-Output "Finished build at $(Get-Date -Format u)"
|
||||
|
||||
|
||||
vsbuild-CLANG:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install pthread:x64-windows
|
||||
vcpkg install pthreads:x64-windows
|
||||
vcpkg install pthread-stubs:x64-windows
|
||||
vcpkg install pthreadpool:x64-windows
|
||||
vcpkg install
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
nmake
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-CLANG
|
||||
path: ${{github.workspace}}/build/bin
|
||||
|
||||
|
||||
|
||||
vsbuild-MSVC:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install pthread:x64-windows
|
||||
vcpkg install pthreads:x64-windows
|
||||
vcpkg install pthread-stubs:x64-windows
|
||||
vcpkg install pthreadpool:x64-windows
|
||||
vcpkg install
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
nmake
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-MSVC
|
||||
path: ${{github.workspace}}/build/bin
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
vsbuild-MSVC-MSBUILD:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup msbuild
|
||||
if: inputs.configuration != 'CMake'
|
||||
uses: microsoft/setup-msbuild@v1
|
||||
- name: Setup VCPKG
|
||||
run: |
|
||||
vcpkg integrate install
|
||||
vcpkg install pthread:x64-windows
|
||||
vcpkg install pthreads:x64-windows
|
||||
vcpkg install pthread-stubs:x64-windows
|
||||
vcpkg install pthreadpool:x64-windows
|
||||
vcpkg install
|
||||
- name: init_submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
call "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
|
||||
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
msbuild dingusppc.sln
|
||||
- name: Upload artifact
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DingusPPC-MSBUILD
|
||||
path: ${{github.workspace}}/build/bin
|
||||
@@ -1,10 +1,14 @@
|
||||
# Ignore binary files
|
||||
out/
|
||||
vcpkg/
|
||||
*.bin
|
||||
|
||||
# Ignore compiled object files
|
||||
.vs/
|
||||
.vscode/
|
||||
*.o
|
||||
*.out
|
||||
*.obj
|
||||
*.d
|
||||
|
||||
# Ignore CMake system files
|
||||
@@ -16,6 +20,9 @@ CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore Visual Studio auto-save recovery folder
|
||||
enc_temp_folder/
|
||||
|
||||
# Ignore CodeLite configuration files
|
||||
*.workspace
|
||||
*.workspace.*
|
||||
@@ -30,6 +37,7 @@ dingusppc.exe
|
||||
# Ignore system files
|
||||
.DS_Store
|
||||
Thumb.db
|
||||
ehthumbs.db
|
||||
|
||||
# IDE ignores
|
||||
build
|
||||
|
||||
+6
-2
@@ -180,9 +180,13 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_compile_options("-DPPC_BENCHMARKS")
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
|
||||
)
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
# $<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
# DingusPPC
|
||||
|
||||
|
||||
## Developers
|
||||
|
||||
- divingkatae
|
||||
- maximumspatium
|
||||
- joevt
|
||||
- mihaip
|
||||
- kkaisershot
|
||||
|
||||
## NT4/PPC fork
|
||||
|
||||
- Wack0
|
||||
|
||||
## DevOps
|
||||
|
||||
- Waqar144
|
||||
- webspacecreations
|
||||
- leap0x7b
|
||||
- sdkmap
|
||||
- dressupgeekout
|
||||
- kth5
|
||||
- dyharlan
|
||||
- roytam1
|
||||
- mrpapersonic
|
||||
- Randrianasulu
|
||||
- lefp
|
||||
- mathstuf
|
||||
|
||||
## Testing
|
||||
|
||||
- LagLifeYT
|
||||
|
||||
## 3rd Party Libraries
|
||||
|
||||
- [Capstone](https://github.com/capstone-engine/capstone)
|
||||
- [CLI11](https://github.com/CLIUtils/CLI11)
|
||||
- [Loguru](https://github.com/emilk/loguru)
|
||||
- [SDL 2](https://github.com/libsdl-org/SDL)
|
||||
|
||||
## Thanks
|
||||
|
||||
- 68kmla
|
||||
- AppleFritter
|
||||
- Archive.org
|
||||
- Bitsavers
|
||||
- Blitter.net
|
||||
- Emaculation
|
||||
- GitHub
|
||||
- PenguinPPC
|
||||
- VirtuallyFun
|
||||
- The makers of Loguru, SDL2, Capstone, and CLI11
|
||||
- The developers of other PowerPC Mac emulators, past and present
|
||||
- All those preserving the software and source code of 68k and PowerPC Macs
|
||||
@@ -57,7 +57,15 @@ You will also have to recursive clone or run
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB and Capstone modules are not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
This is because the CubeB, Capstone, and SDL2 modules are not included by default.
|
||||
|
||||
For SDL2, Linux users may also have to run:
|
||||
|
||||
```
|
||||
sudo apt install libsdl2-dev
|
||||
```
|
||||
|
||||
CLI11 and loguru are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
@@ -81,7 +89,7 @@ emulation. To build the tests, use the following terminal commands:
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DPPC_BUILD_PPC_TESTS=True ..
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DDPPC_BUILD_PPC_TESTS=True ..
|
||||
make testppc
|
||||
```
|
||||
|
||||
|
||||
+78
-32
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/memctrl/mpc106.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <debugger/debugger.h>
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
power_off_reason = po_benchmark_exception;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||
@@ -35,12 +43,15 @@ uint32_t cs_code[] = {
|
||||
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
|
||||
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
|
||||
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
|
||||
0x7C650194, 0x4E800020
|
||||
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;
|
||||
int i, j;
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
@@ -53,7 +64,7 @@ int main(int argc, char** argv) {
|
||||
MPC106* grackle_obj = new MPC106;
|
||||
|
||||
/* we need some RAM */
|
||||
if (!grackle_obj->add_ram_region(0, 0x9000)) {
|
||||
if (!grackle_obj->add_ram_region(0, 0x1000 + test_size)) {
|
||||
LOG_F(ERROR, "Could not create RAM region");
|
||||
delete(grackle_obj);
|
||||
return -1;
|
||||
@@ -61,51 +72,86 @@ int main(int argc, char** argv) {
|
||||
|
||||
constexpr uint64_t tbr_freq = 16705000;
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, tbr_freq);
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, tbr_freq);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
|
||||
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
|
||||
mmu_write_vmem<uint32_t>(0, i * 4, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
mmu_write_vmem<uint8_t>(0x1000+i, rand() % 256);
|
||||
LOG_F(INFO, "Test size: 0x%X", test_size);
|
||||
LOG_F(INFO, "First few bytes:");
|
||||
bool did_lf = false;
|
||||
for (i = 0; i < test_size; i++) {
|
||||
uint8_t val = rand() % 256;
|
||||
mmu_write_vmem<uint8_t>(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] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
enter_debugger();
|
||||
#endif
|
||||
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
uint32_t checksum = ppc_state.gpr[3];
|
||||
|
||||
// run the clock once for cache fill etc.
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
LOG_F(INFO, "Time elapsed (dry run): %lld ns", time_elapsed.count());
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
|
||||
uint64_t overhead = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
|
||||
if (time_elapsed.count() < overhead)
|
||||
overhead = time_elapsed.count();
|
||||
}
|
||||
LOG_F(INFO, "Overhead Time: %lld ns", overhead);
|
||||
|
||||
for (int theproc = 0; theproc < 2; theproc++) {
|
||||
LOG_F(INFO, "Doing %s", theproc ? "ppc_exec_until" : "ppc_exec");
|
||||
for (i = 0; i < test_iterations; i++) {
|
||||
uint64_t best_sample = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
(theproc) ? ppc_exec_until(0xC4) : ppc_exec();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
if (time_elapsed.count() < best_sample)
|
||||
best_sample = time_elapsed.count();
|
||||
}
|
||||
if (ppc_state.gpr[3] != checksum)
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
best_sample -= overhead;
|
||||
LOG_F(INFO, "(%d) %lld ns, %.4lf MiB/s", i+1, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
|
||||
}
|
||||
}
|
||||
|
||||
delete(grackle_obj);
|
||||
|
||||
+8
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -44,16 +44,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// cyclic rotation idioms that modern compilers will
|
||||
// recognize and generate very compact code for
|
||||
// evolving specific machine instructions
|
||||
// involving specific machine instructions
|
||||
|
||||
inline unsigned ROTL_32(unsigned x, unsigned n) {
|
||||
n &= 0x1F;
|
||||
return (x << n) | (x >> (32 - n));
|
||||
if (n)
|
||||
return (x << n) | (x >> (32 - n));
|
||||
return x;
|
||||
}
|
||||
|
||||
inline unsigned ROTR_32(unsigned x, unsigned n) {
|
||||
n &= 0x1F;
|
||||
return (x >> n) | (x << (32 - n));
|
||||
if (n)
|
||||
return (x >> n) | (x << (32 - n));
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -53,6 +53,9 @@ public:
|
||||
|
||||
// Calls all connected slots.
|
||||
void emit(Args... args) {
|
||||
if (!_is_enabled) {
|
||||
return;
|
||||
}
|
||||
for (auto const& it : _slots) {
|
||||
it.second(args...);
|
||||
}
|
||||
@@ -66,9 +69,22 @@ public:
|
||||
_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
|
||||
+70
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -35,11 +35,24 @@ public:
|
||||
uint32_t window_id;
|
||||
};
|
||||
|
||||
enum : uint16_t {
|
||||
// Standard SDL window event types are uint8_t's.
|
||||
// We add our own custom events after that.
|
||||
DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE = 1 << 8,
|
||||
DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE,
|
||||
DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED,
|
||||
DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE,
|
||||
DPPC_WINDOWEVENT_WINDOW_BIGGER,
|
||||
DPPC_WINDOWEVENT_WINDOW_SMALLER,
|
||||
};
|
||||
|
||||
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 {
|
||||
@@ -50,6 +63,8 @@ public:
|
||||
uint32_t flags;
|
||||
uint32_t xrel;
|
||||
uint32_t yrel;
|
||||
uint32_t xabs;
|
||||
uint32_t yabs;
|
||||
uint8_t buttons_state;
|
||||
};
|
||||
|
||||
@@ -63,6 +78,47 @@ public:
|
||||
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() {
|
||||
@@ -72,7 +128,7 @@ public:
|
||||
return event_manager;
|
||||
};
|
||||
|
||||
void poll_events();
|
||||
void poll_events(uint32_t kbd_locale);
|
||||
|
||||
template <typename T>
|
||||
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
|
||||
@@ -89,6 +145,11 @@ public:
|
||||
_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);
|
||||
@@ -101,6 +162,11 @@ public:
|
||||
_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
|
||||
@@ -108,13 +174,14 @@ private:
|
||||
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;
|
||||
uint64_t mouse_motions = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
};
|
||||
|
||||
#endif // EVENT_MANAGER_H
|
||||
+162
-43
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,11 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
EventManager* EventManager::event_manager;
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event);
|
||||
static void toggle_mouse_grab(const SDL_KeyboardEvent &event);
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent& event, uint32_t kbd_locale);
|
||||
|
||||
void EventManager::poll_events()
|
||||
{
|
||||
constexpr int KMOD_ALL = KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI;
|
||||
|
||||
void EventManager::poll_events(uint32_t kbd_locale) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
@@ -41,11 +41,11 @@ void EventManager::poll_events()
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
power_off_reason = po_quit;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
WindowEvent we;
|
||||
WindowEvent we{};
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
@@ -54,17 +54,81 @@ void EventManager::poll_events()
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
// Internal shortcuts to trigger mouse grab, intentionally not
|
||||
// sent to the host.
|
||||
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() == KMOD_LCTRL) {
|
||||
// Internal shortcuts, intentionally not sent to the host.
|
||||
// Control-G: mouse grab
|
||||
if (event.key.keysym.sym == SDLK_g && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
toggle_mouse_grab(event.key);
|
||||
WindowEvent we;
|
||||
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_TOGGLE;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
we.sub_type = DPPC_WINDOWEVENT_MOUSE_GRAB_CHANGED;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
int key_code = get_sdl_event_key_code(event.key);
|
||||
// Control-S: scale quality
|
||||
if (event.key.keysym.sym == SDLK_s && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SCALE_QUALITY_TOGGLE;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-F: fullscreen
|
||||
if (event.key.keysym.sym == SDLK_f && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_FULL_SCREEN_TOGGLE;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control-+: bigger
|
||||
if (event.key.keysym.sym == SDLK_EQUALS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_BIGGER;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Control--: smaller
|
||||
if (event.key.keysym.sym == SDLK_MINUS && (SDL_GetModState() & KMOD_ALL) == KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
WindowEvent we{};
|
||||
we.sub_type = DPPC_WINDOWEVENT_WINDOW_SMALLER;
|
||||
we.window_id = event.window.windowID;
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Ralt+delete => ctrl+alt+del
|
||||
if (event.key.keysym.sym == SDLK_DELETE && ((SDL_GetModState() & KMOD_ALL) == KMOD_RALT) != 0) {
|
||||
KeyboardEvent ke{};
|
||||
ke.key = AdbKey_Control;
|
||||
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
key_downs++;
|
||||
} else {
|
||||
ke.flags = KEYBOARD_EVENT_UP;
|
||||
key_ups++;
|
||||
}
|
||||
|
||||
this->_keyboard_signal.emit(ke);
|
||||
ke.key = AdbKey_Delete;
|
||||
this->_keyboard_signal.emit(ke);
|
||||
return;
|
||||
}
|
||||
int key_code = get_sdl_event_key_code(event.key, kbd_locale);
|
||||
if (key_code != -1) {
|
||||
KeyboardEvent ke;
|
||||
KeyboardEvent ke{};
|
||||
ke.key = key_code;
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
ke.flags = KEYBOARD_EVENT_DOWN;
|
||||
@@ -86,30 +150,96 @@ void EventManager::poll_events()
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION: {
|
||||
MouseEvent me;
|
||||
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;
|
||||
me.buttons_state = 1;
|
||||
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;
|
||||
me.buttons_state = 0;
|
||||
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++;
|
||||
}
|
||||
@@ -120,7 +250,7 @@ void EventManager::poll_events()
|
||||
}
|
||||
|
||||
|
||||
static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
|
||||
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;
|
||||
@@ -255,10 +385,11 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
|
||||
|
||||
//Japanese keyboard
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL3):
|
||||
return AdbKey_JIS_Yen;
|
||||
if (kbd_locale == Jpn_JPN)
|
||||
return AdbKey_JIS_Yen;
|
||||
case SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INTERNATIONAL1):
|
||||
return AdbKey_JIS_Underscore;
|
||||
case 0XBC:
|
||||
case 0XBC:
|
||||
return AdbKey_JIS_KP_Comma;
|
||||
case 0X89:
|
||||
return AdbKey_JIS_Eisu;
|
||||
@@ -284,28 +415,16 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
|
||||
case 0XE8: return AdbKey_6; // E-grave
|
||||
case 0XEC: return AdbKey_LeftBracket; // I-grave
|
||||
case 0XF2: return AdbKey_KeypadMultiply; // O-grave
|
||||
|
||||
// Spanish keyboard
|
||||
case 0XA1: return AdbKey_Comma; // Inverted question mark
|
||||
case 0XBA: return AdbKey_6; // Backslash
|
||||
case 0XE7: return AdbKey_Slash; // C-cedilla
|
||||
case 0XF1: return AdbKey_Semicolon; // N-tilde
|
||||
case 0X4000002f:
|
||||
return AdbKey_LeftBracket; // Acute
|
||||
case 0X40000034:
|
||||
return AdbKey_Semicolon; // Acute
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
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)");
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ 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
|
||||
|
||||
|
||||
+15
-15
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,18 +31,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define USEC_PER_SEC 1E6
|
||||
#define NS_PER_USEC 1000UL
|
||||
#define NS_PER_MSEC 1E6
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
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 function<void()> timer_cb;
|
||||
typedef std::function<void()> timer_cb;
|
||||
|
||||
/** Extend std::priority_queue as suggested here:
|
||||
https://stackoverflow.com/a/36711682
|
||||
@@ -101,7 +99,7 @@ typedef struct TimerInfo {
|
||||
// Custom comparator for sorting our timer queue in ascending order
|
||||
class MyGtComparator {
|
||||
public:
|
||||
bool operator()(const shared_ptr<TimerInfo>& l, const shared_ptr<TimerInfo>& r) {
|
||||
bool operator()(const std::shared_ptr<TimerInfo>& l, const std::shared_ptr<TimerInfo>& r) {
|
||||
return l.get()->timeout_ns > r.get()->timeout_ns;
|
||||
}
|
||||
};
|
||||
@@ -116,7 +114,7 @@ public:
|
||||
};
|
||||
|
||||
// callback for retrieving current time
|
||||
void set_time_now_cb(const function<uint64_t()> &cb) {
|
||||
void set_time_now_cb(const std::function<uint64_t()> &cb) {
|
||||
this->get_time_now = cb;
|
||||
};
|
||||
|
||||
@@ -142,13 +140,15 @@ private:
|
||||
TimerManager(){}; // private constructor to implement a singleton
|
||||
|
||||
// timer queue
|
||||
my_priority_queue<shared_ptr<TimerInfo>, vector<shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
|
||||
my_priority_queue<std::shared_ptr<TimerInfo>, std::vector<std::shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
|
||||
|
||||
function<uint64_t()> get_time_now;
|
||||
function<void()> notify_timer_changes;
|
||||
std::function<uint64_t()> get_time_now;
|
||||
std::function<void()> notify_timer_changes;
|
||||
|
||||
std::atomic<uint32_t> id{0};
|
||||
bool cb_active = false; // true if a timer callback is executing // FIXME: Do we need this? It gets written in main thread and read in audio thread.
|
||||
|
||||
// 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
|
||||
@@ -5,4 +5,10 @@ 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})
|
||||
+367
-332
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,39 +22,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// The Power-specific opcodes for the processor - ppcopcodes.cpp
|
||||
// Any shared opcodes are in ppcopcodes.cpp
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
if ((a ^ b) & (a ^ d) & 0x80000000UL) {
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = uint32_t(0xFFFFFFFFUL << (31 - rot_me));
|
||||
uint32_t m1 = 0xFFFFFFFFU >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFU << (31 - rot_me);
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_abs() {
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_abs(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
ppc_grab_regsda(opcode);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000;
|
||||
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
@@ -63,98 +55,143 @@ void dppc_interpreter::power_abs() {
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
void dppc_interpreter::power_clcs() {
|
||||
void dppc_interpreter::power_clcs(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
ppc_result_d = 64;
|
||||
break;
|
||||
default:
|
||||
ppc_result_d = 0;
|
||||
ppc_grab_da(opcode);
|
||||
switch (reg_a & 15) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 0xC: //instruction cache line size
|
||||
case 0xD: //data cache line size
|
||||
case 0xE: //minimum line size
|
||||
case 0xF: //maximum line size
|
||||
ppc_result_d = is_601 ? 0x40 : 0x20; break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6: ppc_result_d = 0x20; break;
|
||||
case 7: ppc_result_d = is_601 ? 1 : 0; break;
|
||||
case 8:
|
||||
case 9: ppc_result_d = is_601 ? 8 : 4; break;
|
||||
case 0xA:
|
||||
case 0xB: ppc_result_d = is_601 ? 0x8000 : 0x4000; break;
|
||||
}
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_div() {
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_div(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_grab_regsdab(opcode);
|
||||
|
||||
uint64_t dividend = ((uint64_t)ppc_result_a << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t quotient;
|
||||
int32_t remainder;
|
||||
|
||||
if ((ppc_result_a == 0x80000000UL && divisor == -1) || !divisor) {
|
||||
ppc_state.spr[SPR::MQ] = 0;
|
||||
ppc_result_d = 0x80000000UL; // -2^31 aka INT32_MIN
|
||||
if (dividend == -0x80000000 && divisor == -1) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else if (!divisor) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_result_d = uint32_t(dividend / divisor);
|
||||
ppc_state.spr[SPR::MQ] = dividend % divisor;
|
||||
quotient = dividend / divisor;
|
||||
remainder = dividend % divisor;
|
||||
ppc_result_d = uint32_t(quotient);
|
||||
if (ov) {
|
||||
if (((quotient >> 31) + 1) & ~1) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_state.spr[SPR::MQ] = remainder;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_div<RC0, OV0>();
|
||||
template void dppc_interpreter::power_div<RC0, OV1>();
|
||||
template void dppc_interpreter::power_div<RC1, OV0>();
|
||||
template void dppc_interpreter::power_div<RC1, OV1>();
|
||||
template void dppc_interpreter::power_div<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_div<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_div<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_div<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_divs() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_divs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>();
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) >= int32_t(ppc_result_b))\
|
||||
? 0 : ppc_result_b - ppc_result_a;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_divs(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(ppc_cur_instruction);
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(opcode);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
remainder = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
|
||||
ppc_result_d = 0x80000000U;
|
||||
remainder = 0;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else { // normal signed devision
|
||||
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
||||
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_state.spr[SPR::MQ] = remainder;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_divs<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_doz(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
if (ov) {
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
void dppc_interpreter::power_dozi(uint32_t opcode) {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(opcode);
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
@@ -163,62 +200,65 @@ void dppc_interpreter::power_dozi() {
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_lscbx(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint8_t return_value = 0;
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_copied = 0;
|
||||
uint32_t bytes_remaining = bytes_to_load;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
uint32_t ppc_result_d = 0;
|
||||
bool is_match = false;
|
||||
|
||||
// for storing each byte
|
||||
uint32_t bitmask = 0xFF000000;
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_to_load > 0) {
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(opcode, ea);
|
||||
|
||||
ppc_result_d = (ppc_result_d & ~bitmask) | (return_value << shift_amount);
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
reg_d = (reg_d + 1) & 31;
|
||||
bitmask = 0xFF000000;
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
ppc_result_d = 0;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
bitmask >>= 8;
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ppc_effective_address++;
|
||||
bytes_copied++;
|
||||
bytes_to_load--;
|
||||
ea++;
|
||||
bytes_remaining--;
|
||||
|
||||
if (return_value == matching_byte)
|
||||
if (return_value == matching_byte) {
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store partiallly loaded register if any
|
||||
// store partially loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | bytes_copied;
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (rec) {
|
||||
ppc_state.cr =
|
||||
(ppc_state.cr & 0x0FFFFFFFUL) |
|
||||
(is_match ? CRx_bit::CR_EQ : 0) |
|
||||
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_lscbx<RC0>();
|
||||
template void dppc_interpreter::power_lscbx<RC1>();
|
||||
template void dppc_interpreter::power_lscbx<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_lscbx<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
uint32_t mask_start = ppc_result_d & 31;
|
||||
uint32_t mask_end = ppc_result_b & 31;
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskg(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
@@ -234,17 +274,17 @@ void dppc_interpreter::power_maskg() {
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskg<RC0>();
|
||||
template void dppc_interpreter::power_maskg<true>();
|
||||
template void dppc_interpreter::power_maskg<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_maskg<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskir(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
@@ -253,74 +293,76 @@ void dppc_interpreter::power_maskir() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskir<RC0>();
|
||||
template void dppc_interpreter::power_maskir<true>();
|
||||
template void dppc_interpreter::power_maskir<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_maskir<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint64_t product;
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_mul(uint32_t opcode) {
|
||||
ppc_grab_regsdab(opcode);
|
||||
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
|
||||
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
|
||||
ppc_state.spr[SPR::MQ] = uint32_t(product);
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
uint32_t ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
if (ov) {
|
||||
if (uint64_t(product >> 31) + 1 & ~1) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(uint32_t(product));
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_mul<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_nabs(uint32_t opcode) {
|
||||
ppc_grab_regsda(opcode);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
power_setsoov(ppc_result_a, ppc_result_b, ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_mul<RC0, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>(uint32_t opcode);
|
||||
|
||||
template <bool rec, bool ov>
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = ppc_result_a & 0x80000000 ? ppc_result_a : -ppc_result_a;
|
||||
void dppc_interpreter::power_rlmi(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_mb = (opcode >> 6) & 0x1F;
|
||||
unsigned rot_me = (opcode >> 1) & 0x1F;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t r = ROTL_32(ppc_result_d, ppc_result_b);
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((ppc_cur_instruction & 0x01) == 1)
|
||||
if ((opcode & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_rrib(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_d & 0x80000000) {
|
||||
ppc_result_a |= ((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_result_a |= (0x80000000U >> rot_sh);
|
||||
} else {
|
||||
ppc_result_a &= ~((ppc_result_d & 0x80000000) >> ppc_result_b);
|
||||
ppc_result_a &= ~(0x80000000U >> rot_sh);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
@@ -329,16 +371,16 @@ void dppc_interpreter::power_rrib() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_rrib<RC0>();
|
||||
template void dppc_interpreter::power_rrib<RC1>();
|
||||
template void dppc_interpreter::power_rrib<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_rrib<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sle(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
|
||||
@@ -348,14 +390,14 @@ void dppc_interpreter::power_sle() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sle<RC0>();
|
||||
template void dppc_interpreter::power_sle<RC1>();
|
||||
template void dppc_interpreter::power_sle<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sle<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sleq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
@@ -367,16 +409,15 @@ void dppc_interpreter::power_sleq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sleq<RC0>();
|
||||
template void dppc_interpreter::power_sleq<RC1>();
|
||||
template void dppc_interpreter::power_sleq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sleq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sliq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -384,15 +425,14 @@ void dppc_interpreter::power_sliq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sliq<RC0>();
|
||||
template void dppc_interpreter::power_sliq<RC1>();
|
||||
template void dppc_interpreter::power_sliq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sliq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slliq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
uint32_t r = ROTL_32(ppc_result_d, rot_sh);
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
@@ -403,21 +443,18 @@ void dppc_interpreter::power_slliq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slliq<RC0>();
|
||||
template void dppc_interpreter::power_slliq<RC1>();
|
||||
template void dppc_interpreter::power_slliq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_slliq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sllq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sllq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
|
||||
} else {
|
||||
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1U << rot_sh) - 1)));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
@@ -426,41 +463,41 @@ void dppc_interpreter::power_sllq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sllq<RC0>();
|
||||
template void dppc_interpreter::power_sllq<RC1>();
|
||||
template void dppc_interpreter::power_sllq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sllq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_slq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
} else {
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slq<RC0>();
|
||||
template void dppc_interpreter::power_slq<RC1>();
|
||||
template void dppc_interpreter::power_slq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_slq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraiq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
uint32_t mask = (1U << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
@@ -469,24 +506,24 @@ void dppc_interpreter::power_sraiq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraiq<RC0>();
|
||||
template void dppc_interpreter::power_sraiq<RC1>();
|
||||
template void dppc_interpreter::power_sraiq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sraiq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sraq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1U << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
|
||||
ppc_state.spr[SPR::MQ] = ROTL_32(ppc_result_d, rot_sh);
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -494,17 +531,17 @@ void dppc_interpreter::power_sraq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraq<RC0>();
|
||||
template void dppc_interpreter::power_sraq<RC1>();
|
||||
template void dppc_interpreter::power_sraq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sraq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sre(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -512,75 +549,41 @@ void dppc_interpreter::power_sre() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sre<RC0>();
|
||||
template void dppc_interpreter::power_sre<RC1>();
|
||||
template void dppc_interpreter::power_sre<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sre<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srea() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srea(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
if ((ppc_result_d & 0x80000000UL) && (ppc_result_d & rot_sh)) {
|
||||
ppc_state.spr[SPR::XER] |= 0x20000000UL;
|
||||
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>();
|
||||
template void dppc_interpreter::power_srea<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((rot_sh & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = rot_sh;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sreq<RC0>();
|
||||
template void dppc_interpreter::power_sreq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>();
|
||||
template void dppc_interpreter::power_sriq<RC1>();
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srliq() {
|
||||
ppc_grab_regssa(ppc_cur_instruction);
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srea<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sreq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
|
||||
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -588,20 +591,52 @@ void dppc_interpreter::power_srliq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>();
|
||||
template void dppc_interpreter::power_srliq<RC1>();
|
||||
template void dppc_interpreter::power_sreq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sreq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srlq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sriq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_sriq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srliq(uint32_t opcode) {
|
||||
ppc_grab_regssash(opcode);
|
||||
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srliq<RC1>(uint32_t opcode);
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srlq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ROTR_32(ppc_result_d, rot_sh);
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
@@ -611,21 +646,21 @@ void dppc_interpreter::power_srlq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srlq<RC0>();
|
||||
template void dppc_interpreter::power_srlq<RC1>();
|
||||
template void dppc_interpreter::power_srlq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srlq<RC1>(uint32_t opcode);
|
||||
|
||||
template <bool rec>
|
||||
void dppc_interpreter::power_srq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srq(uint32_t opcode) {
|
||||
ppc_grab_regssab(opcode);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b >= 0x20) {
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
ppc_state.spr[SPR::MQ] = ROTR_32(ppc_result_d, rot_sh);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
@@ -633,5 +668,5 @@ void dppc_interpreter::power_srq() {
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srq<RC0>();
|
||||
template void dppc_interpreter::power_srq<RC1>();
|
||||
template void dppc_interpreter::power_srq<RC0>(uint32_t opcode);
|
||||
template void dppc_interpreter::power_srq<RC1>(uint32_t opcode);
|
||||
+118
-117
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define _CRT_SECURE_NO_WARNINGS /* shut up MSVC regarding the unsafe strcpy/strcat */
|
||||
|
||||
#include "ppcdisasm.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <functional> /* without this, MSVC doesn't understand std::function */
|
||||
#include <iostream>
|
||||
@@ -286,52 +287,52 @@ const char* spr_index31[32] = {
|
||||
|
||||
/** various formatting helpers. */
|
||||
void fmt_oneop(PPCDisasmContext* ctx, const char* opc, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opc, src);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opc, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
}
|
||||
|
||||
void fmt_oneop_out(PPCDisasmContext* ctx, const char* opc, int dst) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opc, dst);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opc, dst);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", opc, dst, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_in(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", opc, dst, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_in(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_simm(PPCDisasmContext* ctx, const char* opc, int dst, int imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, %s0x%X", opc, dst, (imm < 0) ? "-" : "", abs(imm));
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, %s0x%X", opc, dst, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_fromspr(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8spr%d, spr%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s pr%d, spr%d", opc, dst, src);
|
||||
add_reg_in(ctx, "spr%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_tospr(PPCDisasmContext* ctx, const char* opc, int dst, int src) {
|
||||
ctx->instr_str = my_sprintf("%-8sspr%d, r%d", opc, dst, src);
|
||||
ctx->instr_str = my_sprintf("%-7s spr%d, r%d", opc, dst, src);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "spr%d", dst);
|
||||
}
|
||||
|
||||
void fmt_twoop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1) {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opc, dst, src1);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opc, dst, src1);
|
||||
add_reg_in(ctx, "f%d", src1);
|
||||
add_reg_out(ctx, "f%d", dst);
|
||||
}
|
||||
|
||||
void fmt_threeop(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, r%d", opc, dst, src1, src2);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, r%d", opc, dst, src1, src2);
|
||||
add_reg_in(ctx, "r%d", src1);
|
||||
add_reg_in(ctx, "r%d", src2);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
@@ -345,32 +346,32 @@ void fmt_threeop_store(PPCDisasmContext* ctx, const char* opc, int dst, int src1
|
||||
}
|
||||
|
||||
void fmt_threeop_crb(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d, crb%d, crb%d", opc, dst, src1, src2);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d, crb%d, crb%d", opc, dst, src1, src2);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
void fmt_threeop_uimm(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, 0x%X", opc, dst, src1, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, 0x%X", opc, dst, src1, imm);
|
||||
add_reg_in(ctx, "r%d", src1);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_threeop_simm(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %s0x%X", opc, dst, src1, (imm < 0) ? "-" : "", abs(imm));
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %s0x%X", opc, dst, src1, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_in(ctx, "r%d", src1);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
|
||||
void fmt_threeop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2) {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d, f%d", opc, dst, src1, src2);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d, f%d", opc, dst, src1, src2);
|
||||
add_reg_in(ctx, "f%d", src1);
|
||||
add_reg_in(ctx, "f%d", src2);
|
||||
add_reg_out(ctx, "f%d", dst);
|
||||
}
|
||||
|
||||
void fmt_fourop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1, int src2, int src3) {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d, f%d, f%d", opc, dst, src1, src2, src3);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d, f%d, f%d", opc, dst, src1, src2, src3);
|
||||
add_reg_in(ctx, "f%d", src1);
|
||||
add_reg_in(ctx, "f%d", src2);
|
||||
add_reg_in(ctx, "f%d", src3);
|
||||
@@ -379,12 +380,12 @@ void fmt_fourop_flt(PPCDisasmContext* ctx, const char* opc, int dst, int src1, i
|
||||
|
||||
void fmt_rotateop(PPCDisasmContext* ctx, const char* opc, int dst, int src, int sh, int mb, int me, bool imm) {
|
||||
if (imm) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
}
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, r%d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, r%d, %d, %d", opc, dst, src, sh, mb, me);
|
||||
add_reg_in(ctx, "r%d", src);
|
||||
add_reg_in(ctx, "r%d", sh);
|
||||
add_reg_out(ctx, "r%d", dst);
|
||||
@@ -394,7 +395,7 @@ void fmt_rotateop(PPCDisasmContext* ctx, const char* opc, int dst, int src, int
|
||||
/* Opcodes */
|
||||
|
||||
void opc_illegal(PPCDisasmContext* ctx) {
|
||||
ctx->instr_str = my_sprintf("%-8s0x%08X", "dc.l", ctx->instr_code);
|
||||
ctx->instr_str = my_sprintf("%-7s 0x%08X", "dc.l", ctx->instr_code);
|
||||
}
|
||||
|
||||
void opc_twi(PPCDisasmContext* ctx) {
|
||||
@@ -409,12 +410,12 @@ void opc_twi(PPCDisasmContext* ctx) {
|
||||
|
||||
if (strlen(opcode) > 0) {
|
||||
strcat(opcode, "i");
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0x%X", opcode, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0x%X", opcode, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, 0x%X", "twi", to, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, r%d, 0x%X", "twi", to, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
}
|
||||
|
||||
@@ -478,7 +479,7 @@ void fmt_rot_imm(PPCDisasmContext* ctx, const char* opc, int ra, int rs, int n)
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %d", opcode, ra, rs, n);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d", opcode, ra, rs, n);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "r%d", ra);
|
||||
}
|
||||
@@ -492,7 +493,7 @@ void fmt_rot_2imm(PPCDisasmContext* ctx, const char* opc, int ra, int rs, int n,
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d, %d, %d", opcode, ra, rs, n, b);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d, %d, %d", opcode, ra, rs, n, b);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "r%d", ra);
|
||||
}
|
||||
@@ -630,13 +631,13 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (!ls) {
|
||||
if ((ctx->instr_code >> 26) & 0x1) {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, 0x%X", "cmpwi", crfd, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, 0x%X", "cmpwi", crfd, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8scr%d, r%d, %s0x%X", "cmplwi", crfd, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
"%-7s cr%d, r%d, %s0x%X", "cmplwi", crfd, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
@@ -645,13 +646,13 @@ void opc_cmp_i_li(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((ctx->instr_code >> 26) & 0x1) {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d, r%d, 0x%X", "cmpi", crfd, ls, ra, imm);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, %d, r%d, 0x%X", "cmpi", crfd, ls, ra, imm);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8scr%d, %d, r%d, %s0x%X", "cmpli", crfd, ls, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
"%-7s cr%d, %d, r%d, %s0x%X", "cmpli", crfd, ls, ra, (imm < 0) ? "-" : "", abs(imm));
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
@@ -668,7 +669,7 @@ void opc_bool_im(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (index == 0) {
|
||||
if (imm == 0 && !ra && !rs && !imm) { /* unofficial, produced by IDA */
|
||||
ctx->instr_str = my_sprintf("%-8s", "nop");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "nop");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -701,7 +702,7 @@ void generic_bcx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi, uint32_t dst)
|
||||
if (ctx->instr_code & 2) {
|
||||
strcat(opcode, "a"); /* add suffix "a" if the AA bit is set */
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8s%d, %d, 0x%08X", opcode, bo, bi, dst);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, %d, 0x%08X", opcode, bo, bi, dst);
|
||||
}
|
||||
|
||||
void generic_bcctrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
@@ -718,7 +719,7 @@ void generic_bcctrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
add_reg_out(ctx, "lr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, %d, 0x%08X", opcode, bo, bi);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, %d, 0x%08X", opcode, bo, bi);
|
||||
}
|
||||
|
||||
void generic_bclrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
@@ -739,7 +740,7 @@ void generic_bclrx(PPCDisasmContext* ctx, uint32_t bo, uint32_t bi) {
|
||||
add_reg_out(ctx, "lr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, %d, 0x%08X", opcode, bo, bi);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, %d, 0x%08X", opcode, bo, bi);
|
||||
}
|
||||
|
||||
void opc_bcx(PPCDisasmContext* ctx) {
|
||||
@@ -758,7 +759,7 @@ void opc_bcx(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((bo & 0x14) == 0x14) {
|
||||
ctx->instr_str = my_sprintf("%-8s0x%08X", bx_mnem[0], dst);
|
||||
ctx->instr_str = my_sprintf("%-7s 0x%08X", bx_mnem[0], dst);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -799,7 +800,7 @@ void opc_bcx(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, (ctx->instr_code & 0x8000) ? "-" : "+");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%s0x%08X", opcode, operands, dst);
|
||||
ctx->instr_str = my_sprintf("%-7s %s0x%08X", opcode, operands, dst);
|
||||
}
|
||||
|
||||
void opc_bcctrx(PPCDisasmContext* ctx) {
|
||||
@@ -821,7 +822,7 @@ void opc_bcctrx(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((bo & 0x14) == 0x14) {
|
||||
ctx->instr_str = my_sprintf("%-8s", bcctrx_mnem[ctx->instr_code & 1]);
|
||||
ctx->instr_str = my_sprintf("%-7s ", bcctrx_mnem[ctx->instr_code & 1]);
|
||||
add_reg_in(ctx, "ctr");
|
||||
if (ctx->instr_code & 1) {
|
||||
add_reg_out(ctx, "lr");
|
||||
@@ -849,7 +850,7 @@ void opc_bcctrx(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, "+");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%s", opcode, operands);
|
||||
ctx->instr_str = my_sprintf("%-7s %s", opcode, operands);
|
||||
}
|
||||
|
||||
void opc_bclrx(PPCDisasmContext* ctx) {
|
||||
@@ -867,7 +868,7 @@ void opc_bclrx(PPCDisasmContext* ctx) {
|
||||
}
|
||||
|
||||
if ((bo & 0x14) == 0x14) {
|
||||
ctx->instr_str = my_sprintf("%-8s", bclrx_mnem[ctx->instr_code & 1]);
|
||||
ctx->instr_str = my_sprintf("%-7s ", bclrx_mnem[ctx->instr_code & 1]);
|
||||
add_reg_in(ctx, "lr");
|
||||
if (ctx->instr_code & 1) {
|
||||
add_reg_out(ctx, "lr");
|
||||
@@ -911,21 +912,21 @@ void opc_bclrx(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, "+");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%s", opcode, operands);
|
||||
ctx->instr_str = my_sprintf("%-7s %s", opcode, operands);
|
||||
}
|
||||
|
||||
void opc_bx(PPCDisasmContext* ctx) {
|
||||
uint32_t dst = ((ctx->instr_code & 2) ? 0 : ctx->instr_addr) +
|
||||
SIGNEXT(ctx->instr_code & 0x3FFFFFC, 25);
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s0x%08X", bx_mnem[ctx->instr_code & 3], dst);
|
||||
ctx->instr_str = my_sprintf("%-7s 0x%08X", bx_mnem[ctx->instr_code & 3], dst);
|
||||
if (ctx->instr_code & 1) {
|
||||
add_reg_in(ctx, "lr");
|
||||
}
|
||||
}
|
||||
|
||||
void opc_sc(PPCDisasmContext* ctx) {
|
||||
ctx->instr_str = my_sprintf("%-8s", "sc");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "sc");
|
||||
}
|
||||
|
||||
void opc_group19(PPCDisasmContext* ctx) {
|
||||
@@ -958,7 +959,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
|
||||
switch (ext_opc) {
|
||||
case 0:
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, cr%d", "mcrf", (rs >> 2), (ra >> 2));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, cr%d", "mcrf", (rs >> 2), (ra >> 2));
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -967,7 +968,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 33:
|
||||
if (ctx->simplified && (ra == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crnor", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crnor", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -975,7 +976,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
}
|
||||
return;
|
||||
case 50:
|
||||
ctx->instr_str = my_sprintf("%-8s", "rfi");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "rfi");
|
||||
add_reg_in(ctx, "msr");
|
||||
add_reg_in(ctx, "srr0");
|
||||
add_reg_in(ctx, "srr1");
|
||||
@@ -983,7 +984,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 129:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crandc", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crandc", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -991,15 +992,15 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
}
|
||||
return;
|
||||
case 150:
|
||||
ctx->instr_str = my_sprintf("%-8s", "isync");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "isync");
|
||||
return;
|
||||
case 193:
|
||||
if (ctx->simplified && (rs == ra) && (rs == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", "crclr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d", "crclr", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else if (ctx->simplified && ((rs != ra) || (rs != rb))) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crxor", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crxor", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -1008,7 +1009,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 225:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crnand", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crnand", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -1017,7 +1018,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 257:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crand", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crand", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -1026,11 +1027,11 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 289:
|
||||
if (ctx->simplified && (rs == ra) && (rs == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", "crset", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d", "crset", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else if (ctx->simplified && ((rs != ra) || (rs != rb))) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "creqv", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "creqv", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -1039,7 +1040,7 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 417:
|
||||
if (ctx->simplified) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "crorc", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "crorc", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
} else {
|
||||
@@ -1048,12 +1049,12 @@ void opc_group19(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
case 449:
|
||||
if (ctx->simplified && (ra == rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d, crb%d", "crmove", rs, ra);
|
||||
ctx->instr_str = my_sprintf("%-7s crb%d, crb%d", "crmove", rs, ra);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else if (ctx->simplified && (ra != rb)) {
|
||||
ctx->instr_str = my_sprintf("%-8s%s, %s, %s", "cror", operand1, operand2, operand3);
|
||||
ctx->instr_str = my_sprintf("%-7s %s, %s, %s", "cror", operand1, operand2, operand3);
|
||||
add_reg_in(ctx, "cr");
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
@@ -1148,7 +1149,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if ((ra != 0) || (rb != 0) || rc_set)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "mtmsr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "mtmsr", rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "msr");
|
||||
}
|
||||
@@ -1156,33 +1157,33 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ra & 16)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d", "mtsr", ra, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, r%d", "mtsr", ra, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "sr%d", ra);
|
||||
}
|
||||
} else if (index == 7) { /* mtsrin */
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "mtsrin", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "mtsrin", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
std::string reg_name = add_reg_in(ctx, "r%d", rb);
|
||||
uint64_t reg_val = get_reg(reg_name);
|
||||
add_reg_out(ctx, "sr%d", reg_val >> 28);
|
||||
} else if (index == 9) { /* tlbie */
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "tlbie", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "tlbie", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
} else if (index == 11) { /* tlbia */
|
||||
ctx->instr_str = my_sprintf("%-8s", "tlbia");
|
||||
ctx->instr_str = my_sprintf("%-7s ", "tlbia");
|
||||
} else if (index == 30) { /* tlbld - 603 only */
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbld", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%s", "tlbld", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
} else if (index == 30) { /* tlbli - 603 only */
|
||||
if (!rs && !ra)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbli", rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%s", "tlbli", rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
}
|
||||
@@ -1238,7 +1239,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
fmt_twoop(ctx, opcode, rs, ra);
|
||||
fmt_twoop(ctx, opcode, ra, rs);
|
||||
|
||||
return;
|
||||
|
||||
@@ -1321,7 +1322,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
@@ -1338,7 +1339,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
}
|
||||
@@ -1363,7 +1364,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
}
|
||||
} else if ((index == 18) || (index == 26)) { /* sync, eieio */
|
||||
ctx->instr_str = my_sprintf("%-8s", opcode);
|
||||
ctx->instr_str = my_sprintf("%-7s ", opcode);
|
||||
return;
|
||||
}
|
||||
/* dcba, dcbf, dcbi, dcbst, dcbt, dcbz, icbi */
|
||||
@@ -1375,7 +1376,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8s0, r%d", opcode, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s 0, r%d", opcode, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
else
|
||||
@@ -1383,7 +1384,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
}
|
||||
} else if (index == 17) { /* tlbsync */
|
||||
ctx->instr_str = my_sprintf("%-8s", opcode);
|
||||
ctx->instr_str = my_sprintf("%-7s ", opcode);
|
||||
return;
|
||||
} else {
|
||||
opc_illegal(ctx);
|
||||
@@ -1407,13 +1408,13 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (!(rs & 1)) {
|
||||
if ((rs >> 2) == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "cmpw", ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "cmpw", ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
return;
|
||||
} else {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmpw", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, r%d", "cmpw", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1422,7 +1423,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmp", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, r%d", "cmp", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1435,14 +1436,14 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
strcpy(opcode, trap_cond[rs]);
|
||||
|
||||
if (strlen(opcode) != 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opcode, ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", opcode, ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "tw", rs, ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, r%d, r%d", "tw", rs, ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
}
|
||||
@@ -1456,7 +1457,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
opc_illegal(ctx);
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", "lwarx", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", "lwarx", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
}
|
||||
@@ -1483,9 +1484,9 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ctx->simplified) {
|
||||
if (!(rs & 1)) {
|
||||
if ((rs >> 2) == 0)
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "cmplw", ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "cmplw", ra, rb);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d, r%d", "cmplw", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, r%d, r%d", "cmplw", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -1496,14 +1497,14 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
|
||||
else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8scr%d, %d, r%d, r%d", "cmpl", (rs >> 2), (rs & 1), ra, rb);
|
||||
"%-7s cr%d, %d, r%d, r%d", "cmpl", (rs >> 2), (rs & 1), ra, rb);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
break;
|
||||
case 83: /* mfmsr */
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "mfmsr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "mfmsr", rs);
|
||||
add_reg_in(ctx, "msr");
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
break;
|
||||
@@ -1512,10 +1513,10 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
if (((ctx->instr_code >> 12) & 0xFF) == 0xFF)
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", "mtcr", rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", "mtcr", rs);
|
||||
else
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8s0x%02X, r%d", "mtcrf", (ctx->instr_code >> 12) & 0xFF, rs);
|
||||
"%-7s 0x%02X, r%d", "mtcrf", (ctx->instr_code >> 12) & 0xFF, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
@@ -1531,7 +1532,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "xer");
|
||||
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1544,42 +1545,42 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
case 0:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index0[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index0[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 8:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index8[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index8[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 16:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index16[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index16[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 29:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index29[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index29[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 30:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index30[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index30[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
case 31:
|
||||
strcpy(opcode, "mf");
|
||||
strcat(opcode, spr_index31[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "%s", spr_index31[spr_low]);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
return;
|
||||
@@ -1600,7 +1601,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, %d", "mftb", rs, ref_spr);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, %d", "mftb", rs, ref_spr);
|
||||
if (ref_spr == 268) {
|
||||
add_reg_in(ctx, "tbl");
|
||||
} else if (ref_spr == 269) {
|
||||
@@ -1616,7 +1617,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
case 0:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index0[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
if (spr_low == 0x16) { /* decrementer */
|
||||
add_reg_in(ctx, "msr");
|
||||
@@ -1626,35 +1627,35 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
case 8:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index8[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index8[spr_low]);
|
||||
return;
|
||||
case 16:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index16[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index16[spr_low]);
|
||||
return;
|
||||
case 29:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index29[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index29[spr_low]);
|
||||
return;
|
||||
case 30:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index30[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index30[spr_low]);
|
||||
return;
|
||||
case 31:
|
||||
strcpy(opcode, "mt");
|
||||
strcat(opcode, spr_index31[spr_low]);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d", opcode, rs);
|
||||
add_reg_in(ctx, "r%d", rs);
|
||||
add_reg_out(ctx, "%s", spr_index31[spr_low]);
|
||||
return;
|
||||
@@ -1663,7 +1664,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
fmt_twoop_tospr(ctx, "mtspr", ref_spr, rs);
|
||||
break;
|
||||
case 512: /* mcrxr */
|
||||
ctx->instr_str = my_sprintf("%-8scr%d", "mcrxr", (rs >> 2));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d", "mcrxr", (rs >> 2));
|
||||
add_reg_in(ctx, "xer");
|
||||
add_reg_out(ctx, "cr");
|
||||
add_reg_out(ctx, "xer");
|
||||
@@ -1683,7 +1684,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
opc_illegal(ctx);
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", "lswx", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", "lswx", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1705,7 +1706,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (ra & 16)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, %d", "mfsr", rs, ra);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, %d", "mfsr", rs, ra);
|
||||
add_reg_in(ctx, "sr%d", ra);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
}
|
||||
@@ -1718,7 +1719,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
rb = 32;
|
||||
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, %x", "lswi", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, %x", "lswi", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1728,7 +1729,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
break;
|
||||
case 659: /* mfsrin */
|
||||
{
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "mfsrin", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, r%d", "mfsrin", rs, rb);
|
||||
add_reg_out(ctx, "r%d", rs);
|
||||
std::string reg_name = add_reg_in(ctx, "r%d", rb);
|
||||
uint64_t reg_val = get_reg(reg_name);
|
||||
@@ -1741,7 +1742,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
return;
|
||||
} else {
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, r%d", "stswx", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, r%d", "stswx", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -1759,7 +1760,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
rb = 32;
|
||||
|
||||
if (ra == 0) {
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, 0, %d", "stswi", rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s r%d, 0, %d", "stswi", rs, rb);
|
||||
add_reg_in(ctx, "r%d", rb);
|
||||
add_reg_out(ctx, "r%d", rs); /* string operation: additional registers are affected */
|
||||
}
|
||||
@@ -2071,7 +2072,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if ((rc != 0) || (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2138,7 +2139,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rs & 3)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, f%d, f%d", "fcmpu", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, f%d, f%d", "fcmpu", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "f%d", ra);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -2153,7 +2154,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2168,7 +2169,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2183,7 +2184,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
@@ -2193,7 +2194,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rs & 3)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, f%d, f%d", "fcmpo", (rs >> 2), ra, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, f%d, f%d", "fcmpo", (rs >> 2), ra, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_in(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "cr");
|
||||
@@ -2207,7 +2208,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s %d", opcode, rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
break;
|
||||
case 40: /* fneg */
|
||||
@@ -2221,7 +2222,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2229,7 +2230,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
case 64:
|
||||
strcpy(opcode, "mcrfs");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, cr%d", opcode, (rs >> 2), (ra >> 2));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, cr%d", opcode, (rs >> 2), (ra >> 2));
|
||||
add_reg_in(ctx, "fpscr");
|
||||
add_reg_out(ctx, "cr");
|
||||
break;
|
||||
@@ -2241,7 +2242,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s %d", opcode, rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
break;
|
||||
case 72: /* fmr */
|
||||
@@ -2255,7 +2256,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2270,7 +2271,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
ctx->instr_str = my_sprintf("%-7s cr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
add_reg_out(ctx, "fpscr");
|
||||
}
|
||||
break;
|
||||
@@ -2284,7 +2285,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2299,7 +2300,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d, f%d", opcode, rs, rb);
|
||||
add_reg_in(ctx, "f%d", rb);
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2315,7 +2316,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if ((ra != 0) || (rb != 0))
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
ctx->instr_str = my_sprintf("%-8sf%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-7s f%d", opcode, rs);
|
||||
add_reg_in(ctx, "fpscr");
|
||||
add_reg_out(ctx, "f%d", rs);
|
||||
}
|
||||
@@ -2328,7 +2329,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
add_reg_out(ctx, "cr");
|
||||
}
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d", opcode, fm, rb);
|
||||
ctx->instr_str = my_sprintf("%-7s %d, f%d", opcode, fm, rb);
|
||||
add_reg_in(ctx, "f%d", rs);
|
||||
add_reg_out(ctx, "fpscr");
|
||||
break;
|
||||
@@ -2357,11 +2358,11 @@ void opc_intldst(PPCDisasmContext* ctx) {
|
||||
|
||||
if (ra) {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sr%d, %s0x%X(r%d)", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
"%-7s r%d, %s0x%X(r%d)", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
} else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sr%d, %s0x%X", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
"%-7s r%d, %s0x%X", opc_int_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2385,11 +2386,11 @@ void opc_fltldst(PPCDisasmContext* ctx) {
|
||||
|
||||
if (ra) {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sf%d, %s0x%X(r%d)", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
"%-7s f%d, %s0x%X(r%d)", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm), ra);
|
||||
add_reg_in(ctx, "r%d", ra);
|
||||
} else {
|
||||
ctx->instr_str = my_sprintf(
|
||||
"%-8sf%d, %s0x%X", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
"%-7s f%d, %s0x%X", opc_flt_ldst[opcode], rd, ((imm < 0) ? "-" : ""), abs(imm));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+321
-269
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <endianswap.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
@@ -46,7 +47,7 @@ enum EXEC_MODE:uint32_t {
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
typedef void (*PPCOpcode)(uint32_t opcode);
|
||||
|
||||
union FPR_storage {
|
||||
double dbl64_r; // double floating-point representation
|
||||
@@ -84,17 +85,18 @@ extern SetPRS ppc_state;
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum SPR : int {
|
||||
MQ = 0,
|
||||
MQ = 0, // MQ (601)
|
||||
XER = 1,
|
||||
RTCU_U = 4, // user RTCU
|
||||
RTCL_U = 5, // user RTCL
|
||||
RTCU_U = 4, // user mode RTCU (601)
|
||||
RTCL_U = 5, // user mode RTCL (601)
|
||||
DEC_U = 6, // user mode decrementer (601)
|
||||
LR = 8,
|
||||
CTR = 9,
|
||||
DSISR = 18,
|
||||
DAR = 19,
|
||||
RTCU_S = 20, // supervisor RTCU
|
||||
RTCL_S = 21, // supervisor RTCL
|
||||
DEC = 22, // decrementer
|
||||
RTCU_S = 20, // supervisor RTCU (601)
|
||||
RTCL_S = 21, // supervisor RTCL (601)
|
||||
DEC_S = 22, // supervisor decrementer
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
@@ -175,15 +177,16 @@ extern uint64_t rtc_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint32_t dec_wr_value;
|
||||
extern uint32_t tbr_freq_ghz;
|
||||
extern uint32_t tbr_freq_shift;
|
||||
extern uint64_t tbr_period_ns;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
/* Flags for controlling interpreter execution. */
|
||||
enum {
|
||||
EXEF_BRANCH = 1 << 0,
|
||||
EXEF_EXCEPTION = 1 << 1,
|
||||
EXEF_RFI = 1 << 2,
|
||||
EXEF_TIMER = 1 << 7
|
||||
EXEF_BRANCH = 1 << 0, // Branch taken, target PC is is in ppc_next_instruction_address
|
||||
EXEF_EXCEPTION = 1 << 1, // Exception handler invoked
|
||||
EXEF_RFI = 1 << 2, // RFI instruction executed
|
||||
EXEF_OPC_DECODER = 1 << 3, // Opcode decoder has changed
|
||||
};
|
||||
|
||||
enum CR_select : int32_t {
|
||||
@@ -242,22 +245,54 @@ enum FPSCR : uint32_t {
|
||||
FX = 1UL << 31
|
||||
};
|
||||
|
||||
/** Bit definitions for the Machine State Register (MSR). */
|
||||
enum MSR : int {
|
||||
LE = 0x1, //little endian mode
|
||||
RI = 0x2,
|
||||
DR = 0x10,
|
||||
IR = 0x20,
|
||||
IP = 0x40,
|
||||
FE1 = 0x100,
|
||||
BE = 0x200,
|
||||
SE = 0x400,
|
||||
FE0 = 0x800,
|
||||
ME = 0x1000,
|
||||
FP = 0x2000,
|
||||
PR = 0x4000,
|
||||
EE = 0x8000, //external interrupt
|
||||
ILE = 0x10000,
|
||||
POW = 0x40000
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// 64-bit // 32-bit // Notes for MPC601 (601), PowerPC (PPC),
|
||||
// // // MPC750 (750), Altivec (AV), Power ISA (ISA)
|
||||
// ----------------------------------------------------------------------------------------
|
||||
LE = (1 << (63 - 63)), // 31 // Little-endian mode enable (not 601);
|
||||
// Little-Endian Mode (ISA)
|
||||
RI = (1 << (63 - 62)), // 30 // Recoverable exception (not 601);
|
||||
// Recoverable Interrupt (ISA)
|
||||
PM = (1 << (63 - 61)), // 29 // Performance monitor marked mode (750);
|
||||
// Performance Monitor Mark (PMM for ISA)
|
||||
// = (1 << (63 - 60)), // 28 // Reserved
|
||||
DR = (1 << (63 - 59)), // 27 // Data address translation (DT on 601);
|
||||
// Data Relocate (ISA)
|
||||
IR = (1 << (63 - 58)), // 26 // Instruction address translation (IT on 601);
|
||||
// Instruction Relocate (ISA)
|
||||
IP = (1 << (63 - 57)), // 25 // Exception prefix (EP); Reserved (ISA)
|
||||
// = (1 << (63 - 56)), // 24 // Reserved (AL for POWER)
|
||||
FE1 = (1 << (63 - 55)), // 23 // Floating-point exception mode 1
|
||||
BE = (1 << (63 - 54)), // 22 // Branch trace enable (Optional, not 601);
|
||||
// Trace Enable (TE): Branch Trace (ISA)
|
||||
SE = (1 << (63 - 53)), // 21 // Single-step trace enable (Optional);
|
||||
// Trace Enable (TE): Single Step Trace (ISA)
|
||||
FE0 = (1 << (63 - 52)), // 20 // Floating-point exception mode 0
|
||||
ME = (1 << (63 - 51)), // 19 // Machine check enable;
|
||||
// Machine Check Interrupt Enable (ISA)
|
||||
FP = (1 << (63 - 50)), // 18 // Floating-point available
|
||||
PR = (1 << (63 - 49)), // 17 // Privilege level; Problem State (ISA)
|
||||
EE = (1 << (63 - 48)), // 16 // External exception enable (601);
|
||||
// External interrupt enable
|
||||
// ----------------------------------------------------------------------------------------
|
||||
ILE = (1 << (63 - 47)), // 15 // Exception little-endian mode (not 601, not ISA)
|
||||
TGPR = (1 << (63 - 46)), // 14 // Temporary GPR remapping (603e)
|
||||
POW = (1 << (63 - 45)), // 13 // Power management enable (not 601, not ISA)
|
||||
// = (1 << (63 - 44)), // 12 // Reserved
|
||||
// = (1 << (63 - 42)), // 10 // Reserved
|
||||
// S = (1 << (63 - 41)), // 9 // Secure (ISA)
|
||||
// VSX = (1 << (63 - 40)), // 8 // VSX Available (ISA)
|
||||
// = (1 << (63 - 39)), // 7 // Reserved
|
||||
VEC = (1 << (63 - 38)), // 6 // AltiVec available (AV); Vector Available (ISA)
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// HV = (1ULL << (63 - 3)), // // Hypervisor State (ISA)
|
||||
// ISF = (1ULL << (63 - 2)), // // Exception 64-bit mode (optional, PPC)
|
||||
// = (1ULL << (63 - 1)), // // Reserved
|
||||
// SF = (1ULL << (63 - 0)), // // Sixty-four bit mode (PowerPC, PowerISA)
|
||||
// ----------------------------------------------------------------------------------------
|
||||
};
|
||||
|
||||
enum XER : uint32_t {
|
||||
@@ -298,28 +333,25 @@ enum Exc_Cause : uint32_t {
|
||||
TRAP = 1 << (31 - 14),
|
||||
};
|
||||
|
||||
#ifdef EXEC_FLAGS_ATOMIC
|
||||
extern std::atomic<unsigned> exec_flags;
|
||||
#else
|
||||
extern unsigned exec_flags;
|
||||
#endif
|
||||
|
||||
extern jmp_buf exc_env;
|
||||
|
||||
extern bool grab_return;
|
||||
|
||||
enum Po_Cause : int {
|
||||
po_none,
|
||||
po_starting_up,
|
||||
po_quit,
|
||||
po_quitting,
|
||||
po_shut_down,
|
||||
po_shutting_down,
|
||||
po_restarting,
|
||||
po_restart,
|
||||
po_restarting,
|
||||
po_disassemble_on,
|
||||
po_disassemble_off,
|
||||
po_enter_debugger,
|
||||
po_entered_debugger,
|
||||
po_signal_interrupt,
|
||||
po_benchmark_exception
|
||||
};
|
||||
|
||||
extern bool power_on;
|
||||
@@ -328,16 +360,19 @@ extern bool int_pin;
|
||||
extern bool dec_exception_pending;
|
||||
|
||||
extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras
|
||||
// (matches Mac OS 9 environment which can emulate MPC 601 instructions)
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
|
||||
// Make execution deterministic (ignore external input, used a fixed date, etc.)
|
||||
extern bool is_deterministic;
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
|
||||
return READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
// Profiling Stats
|
||||
@@ -349,27 +384,70 @@ extern uint64_t num_int_stores;
|
||||
extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
|
||||
// instruction enums
|
||||
typedef enum {
|
||||
ppc_and = 1,
|
||||
ppc_andc = 2,
|
||||
ppc_eqv = 3,
|
||||
ppc_nand = 4,
|
||||
ppc_nor = 5,
|
||||
ppc_or = 6,
|
||||
ppc_orc = 7,
|
||||
ppc_xor = 8,
|
||||
} logical_fun;
|
||||
|
||||
typedef enum {
|
||||
LK0,
|
||||
LK1,
|
||||
} field_lk;
|
||||
|
||||
typedef enum {
|
||||
AA0,
|
||||
AA1,
|
||||
} field_aa;
|
||||
|
||||
typedef enum {
|
||||
SHFT0,
|
||||
SHFT1,
|
||||
} field_shift;
|
||||
|
||||
typedef enum {
|
||||
RIGHT0,
|
||||
LEFT1,
|
||||
} field_direction;
|
||||
|
||||
typedef enum {
|
||||
RC0,
|
||||
RC1,
|
||||
} field_rc;
|
||||
|
||||
typedef enum {
|
||||
OV0,
|
||||
OV1,
|
||||
} field_ov;
|
||||
|
||||
typedef enum {
|
||||
CARRY0,
|
||||
CARRY1,
|
||||
} field_carry;
|
||||
|
||||
typedef enum {
|
||||
NOT601,
|
||||
IS601,
|
||||
} field_601;
|
||||
|
||||
// Placeholder value for cases where we don't have a currently-executing instruction.
|
||||
constexpr uint32_t NO_OPCODE = 0;
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq);
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_fpu_off();
|
||||
void ppc_illegalop(uint32_t opcode);
|
||||
void ppc_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
template <bool for601> void ppc_opcode19();
|
||||
void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
|
||||
void initialize_ppc_opcode_tables();
|
||||
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
extern uint64_t fp_return_uint64(uint32_t reg);
|
||||
void initialize_ppc_opcode_table();
|
||||
|
||||
void ppc_changecrf0(uint32_t set_result);
|
||||
void set_host_rounding_mode(uint8_t mode);
|
||||
@@ -378,8 +456,8 @@ void update_fpscr(uint32_t new_fpscr);
|
||||
/* Exception handlers. */
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
void ppc_floating_point_exception();
|
||||
void ppc_alignment_exception(uint32_t ea);
|
||||
void ppc_floating_point_exception(uint32_t opcode);
|
||||
void ppc_alignment_exception(uint32_t opcode, uint32_t ea);
|
||||
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
@@ -389,232 +467,204 @@ extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
|
||||
enum bool_fun {
|
||||
bool_and = 1,
|
||||
bool_andc = 2,
|
||||
bool_eqv = 3,
|
||||
bool_nand = 4,
|
||||
bool_nor = 5,
|
||||
bool_or = 6,
|
||||
bool_orc = 7,
|
||||
bool_xor = 8,
|
||||
};
|
||||
|
||||
enum field_setting {
|
||||
LK0 = 0,
|
||||
LK1 = 1,
|
||||
AA0 = 0,
|
||||
AA1 = 1,
|
||||
SHFT0 = 0,
|
||||
SHFT1 = 1,
|
||||
RC0 = 0,
|
||||
RC1 = 1,
|
||||
OV0 = 0,
|
||||
OV1 = 1,
|
||||
CARRY0 = 0,
|
||||
CARRY1 = 1,
|
||||
IS601 = 0,
|
||||
NOT601 = 1
|
||||
};
|
||||
|
||||
namespace dppc_interpreter {
|
||||
template <bool l, bool for601> extern void ppc_bcctr();
|
||||
template <bool l> extern void ppc_bclr();
|
||||
extern void ppc_crand();
|
||||
extern void ppc_crandc();
|
||||
extern void ppc_creqv();
|
||||
extern void ppc_crnand();
|
||||
extern void ppc_crnor();
|
||||
extern void ppc_cror();
|
||||
extern void ppc_crorc();
|
||||
extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
template <field_lk l, field_601 for601> extern void ppc_bcctr(uint32_t opcode);
|
||||
template <field_lk l> extern void ppc_bclr(uint32_t opcode);
|
||||
extern void ppc_crand(uint32_t opcode);
|
||||
extern void ppc_crandc(uint32_t opcode);
|
||||
extern void ppc_creqv(uint32_t opcode);
|
||||
extern void ppc_crnand(uint32_t opcode);
|
||||
extern void ppc_crnor(uint32_t opcode);
|
||||
extern void ppc_cror(uint32_t opcode);
|
||||
extern void ppc_crorc(uint32_t opcode);
|
||||
extern void ppc_crxor(uint32_t opcode);
|
||||
extern void ppc_isync(uint32_t opcode);
|
||||
|
||||
template <int bool_op, bool rec> extern void ppc_do_bool();
|
||||
template <logical_fun logical_op, field_rc rec> extern void ppc_logical(uint32_t opcode);
|
||||
|
||||
template <bool carry, bool rec, bool ov> extern void ppc_add();
|
||||
template <bool rec, bool ov> extern void ppc_adde();
|
||||
template <bool rec, bool ov> extern void ppc_addme();
|
||||
template <bool rec, bool ov> extern void ppc_addze();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
template <bool rec> extern void ppc_cntlzw();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
template <bool rec, bool ov> extern void ppc_divw();
|
||||
template <bool rec, bool ov> extern void ppc_divwu();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
template <class T, bool rec>extern void ppc_exts();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhaux();
|
||||
extern void ppc_lhax();
|
||||
extern void ppc_lhbrx();
|
||||
extern void ppc_lwarx();
|
||||
extern void ppc_lwbrx();
|
||||
template <class T> extern void ppc_lzx();
|
||||
template <class T> extern void ppc_lzux();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
template <bool rec> extern void ppc_mulhwu();
|
||||
template <bool rec> extern void ppc_mulhw();
|
||||
template <bool rec, bool ov> extern void ppc_mullw();
|
||||
template <bool rec, bool ov> extern void ppc_neg();
|
||||
template <bool left, bool rec> extern void ppc_shift();
|
||||
template <bool rec> extern void ppc_sraw();
|
||||
template <bool rec> extern void ppc_srawi();
|
||||
template <class T> extern void ppc_stx();
|
||||
template <class T> extern void ppc_stux();
|
||||
extern void ppc_stfiwx();
|
||||
extern void ppc_sthbrx();
|
||||
extern void ppc_stwcx();
|
||||
extern void ppc_stwbrx();
|
||||
template <bool carry, bool rec, bool ov> extern void ppc_subf();
|
||||
template <bool rec, bool ov> extern void ppc_subfe();
|
||||
template <bool rec, bool ov> extern void ppc_subfme();
|
||||
template <bool rec, bool ov> extern void ppc_subfze();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
extern void ppc_tlbli();
|
||||
extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_adde(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addme(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addze(uint32_t opcode);
|
||||
extern void ppc_cmp(uint32_t opcode);
|
||||
extern void ppc_cmpl(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_cntlzw(uint32_t opcode);
|
||||
extern void ppc_dcbf(uint32_t opcode);
|
||||
extern void ppc_dcbi(uint32_t opcode);
|
||||
extern void ppc_dcbst(uint32_t opcode);
|
||||
extern void ppc_dcbt(uint32_t opcode);
|
||||
extern void ppc_dcbtst(uint32_t opcode);
|
||||
extern void ppc_dcbz(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divw(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divwu(uint32_t opcode);
|
||||
extern void ppc_eciwx(uint32_t opcode);
|
||||
extern void ppc_ecowx(uint32_t opcode);
|
||||
extern void ppc_eieio(uint32_t opcode);
|
||||
template <class T, field_rc rec>extern void ppc_exts(uint32_t opcode);
|
||||
extern void ppc_icbi(uint32_t opcode);
|
||||
extern void ppc_mftb(uint32_t opcode);
|
||||
extern void ppc_lhaux(uint32_t opcode);
|
||||
extern void ppc_lhax(uint32_t opcode);
|
||||
extern void ppc_lhbrx(uint32_t opcode);
|
||||
extern void ppc_lwarx(uint32_t opcode);
|
||||
extern void ppc_lwbrx(uint32_t opcode);
|
||||
template <class T> extern void ppc_lzx(uint32_t opcode);
|
||||
template <class T> extern void ppc_lzux(uint32_t opcode);
|
||||
extern void ppc_mcrxr(uint32_t opcode);
|
||||
extern void ppc_mfcr(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mulhwu(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mulhw(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_mullw(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_neg(uint32_t opcode);
|
||||
template <field_direction shift, field_rc rec> extern void ppc_shift(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_sraw(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_srawi(uint32_t opcode);
|
||||
template <class T> extern void ppc_stx(uint32_t opcode);
|
||||
template <class T> extern void ppc_stux(uint32_t opcode);
|
||||
extern void ppc_stfiwx(uint32_t opcode);
|
||||
extern void ppc_sthbrx(uint32_t opcode);
|
||||
extern void ppc_stwcx(uint32_t opcode);
|
||||
extern void ppc_stwbrx(uint32_t opcode);
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfe(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfme(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfze(uint32_t opcode);
|
||||
extern void ppc_sync(uint32_t opcode);
|
||||
extern void ppc_tlbia(uint32_t opcode);
|
||||
extern void ppc_tlbie(uint32_t opcode);
|
||||
extern void ppc_tlbli(uint32_t opcode);
|
||||
extern void ppc_tlbld(uint32_t opcode);
|
||||
extern void ppc_tlbsync(uint32_t opcode);
|
||||
extern void ppc_tw(uint32_t opcode);
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
extern void ppc_stswi();
|
||||
extern void ppc_stswx();
|
||||
extern void ppc_lswi(uint32_t opcode);
|
||||
extern void ppc_lswx(uint32_t opcode);
|
||||
extern void ppc_stswi(uint32_t opcode);
|
||||
extern void ppc_stswx(uint32_t opcode);
|
||||
|
||||
extern void ppc_mfsr();
|
||||
extern void ppc_mfsrin();
|
||||
extern void ppc_mtsr();
|
||||
extern void ppc_mtsrin();
|
||||
extern void ppc_mfsr(uint32_t opcode);
|
||||
extern void ppc_mfsrin(uint32_t opcode);
|
||||
extern void ppc_mtsr(uint32_t opcode);
|
||||
extern void ppc_mtsrin(uint32_t opcode);
|
||||
|
||||
extern void ppc_mcrf();
|
||||
extern void ppc_mtcrf();
|
||||
extern void ppc_mfmsr();
|
||||
extern void ppc_mfspr();
|
||||
extern void ppc_mtmsr();
|
||||
extern void ppc_mtspr();
|
||||
extern void ppc_mcrf(uint32_t opcode);
|
||||
extern void ppc_mtcrf(uint32_t opcode);
|
||||
extern void ppc_mfmsr(uint32_t opcode);
|
||||
extern void ppc_mfspr(uint32_t opcode);
|
||||
extern void ppc_mtmsr(uint32_t opcode);
|
||||
extern void ppc_mtspr(uint32_t opcode);
|
||||
|
||||
template <bool rec> extern void ppc_mtfsb0();
|
||||
template <bool rec> extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
template <bool rec> extern void ppc_fmr();
|
||||
template <bool for601, bool rec> extern void ppc_mffs();
|
||||
template <bool rec> extern void ppc_mtfsf();
|
||||
template <bool rec> extern void ppc_mtfsfi();
|
||||
template <field_rc rec> extern void ppc_mtfsb0(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mtfsb1(uint32_t opcode);
|
||||
extern void ppc_mcrfs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmr(uint32_t opcode);
|
||||
template <field_601 for601, field_rc rec> extern void ppc_mffs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mtfsf(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_mtfsfi(uint32_t opcode);
|
||||
|
||||
template <bool shift> extern void ppc_addi();
|
||||
template <bool rec> extern void ppc_addic();
|
||||
template <bool shift> extern void ppc_andirc();
|
||||
template <bool l, bool a> extern void ppc_b();
|
||||
template <bool l, bool a> extern void ppc_bc();
|
||||
extern void ppc_cmpi();
|
||||
extern void ppc_cmpli();
|
||||
template <class T> extern void ppc_lz();
|
||||
template <class T> extern void ppc_lzu();
|
||||
extern void ppc_lha();
|
||||
extern void ppc_lhau();
|
||||
extern void ppc_lmw();
|
||||
extern void ppc_mulli();
|
||||
template <bool shift> extern void ppc_ori();
|
||||
extern void ppc_rfi();
|
||||
extern void ppc_rlwimi();
|
||||
extern void ppc_rlwinm();
|
||||
extern void ppc_rlwnm();
|
||||
extern void ppc_sc();
|
||||
template <class T> extern void ppc_st();
|
||||
template <class T> extern void ppc_stu();
|
||||
extern void ppc_stmw();
|
||||
extern void ppc_subfic();
|
||||
extern void ppc_twi();
|
||||
template <bool shift> extern void ppc_xori();
|
||||
template <field_shift shift> extern void ppc_addi(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_addic(uint32_t opcode);
|
||||
template <field_shift shift> extern void ppc_andirc(uint32_t opcode);
|
||||
template <field_lk l, field_aa a> extern void ppc_b(uint32_t opcode);
|
||||
template <field_lk l, field_aa a> extern void ppc_bc(uint32_t opcode);
|
||||
extern void ppc_cmpi(uint32_t opcode);
|
||||
extern void ppc_cmpli(uint32_t opcode);
|
||||
template <class T> extern void ppc_lz(uint32_t opcode);
|
||||
template <class T> extern void ppc_lzu(uint32_t opcode);
|
||||
extern void ppc_lha(uint32_t opcode);
|
||||
extern void ppc_lhau(uint32_t opcode);
|
||||
extern void ppc_lmw(uint32_t opcode);
|
||||
extern void ppc_mulli(uint32_t opcode);
|
||||
template <field_shift shift> extern void ppc_ori(uint32_t opcode);
|
||||
extern void ppc_rfi(uint32_t opcode);
|
||||
extern void ppc_rlwimi(uint32_t opcode);
|
||||
extern void ppc_rlwinm(uint32_t opcode);
|
||||
extern void ppc_rlwnm(uint32_t opcode);
|
||||
extern void ppc_sc(uint32_t opcode);
|
||||
template <class T> extern void ppc_st(uint32_t opcode);
|
||||
template <class T> extern void ppc_stu(uint32_t opcode);
|
||||
extern void ppc_stmw(uint32_t opcode);
|
||||
extern void ppc_subfic(uint32_t opcode);
|
||||
extern void ppc_twi(uint32_t opcode);
|
||||
template <field_shift shift> extern void ppc_xori(uint32_t opcode);
|
||||
|
||||
extern void ppc_lfs();
|
||||
extern void ppc_lfsu();
|
||||
extern void ppc_lfsx();
|
||||
extern void ppc_lfsux();
|
||||
extern void ppc_lfd();
|
||||
extern void ppc_lfdu();
|
||||
extern void ppc_lfdx();
|
||||
extern void ppc_lfdux();
|
||||
extern void ppc_stfs();
|
||||
extern void ppc_stfsu();
|
||||
extern void ppc_stfsx();
|
||||
extern void ppc_stfsux();
|
||||
extern void ppc_stfd();
|
||||
extern void ppc_stfdu();
|
||||
extern void ppc_stfdx();
|
||||
extern void ppc_stfdux();
|
||||
extern void ppc_lfs(uint32_t opcode);
|
||||
extern void ppc_lfsu(uint32_t opcode);
|
||||
extern void ppc_lfsx(uint32_t opcode);
|
||||
extern void ppc_lfsux(uint32_t opcode);
|
||||
extern void ppc_lfd(uint32_t opcode);
|
||||
extern void ppc_lfdu(uint32_t opcode);
|
||||
extern void ppc_lfdx(uint32_t opcode);
|
||||
extern void ppc_lfdux(uint32_t opcode);
|
||||
extern void ppc_stfs(uint32_t opcode);
|
||||
extern void ppc_stfsu(uint32_t opcode);
|
||||
extern void ppc_stfsx(uint32_t opcode);
|
||||
extern void ppc_stfsux(uint32_t opcode);
|
||||
extern void ppc_stfd(uint32_t opcode);
|
||||
extern void ppc_stfdu(uint32_t opcode);
|
||||
extern void ppc_stfdx(uint32_t opcode);
|
||||
extern void ppc_stfdux(uint32_t opcode);
|
||||
|
||||
template <bool rec> extern void ppc_fadd();
|
||||
template <bool rec> extern void ppc_fsub();
|
||||
template <bool rec> extern void ppc_fmul();
|
||||
template <bool rec> extern void ppc_fdiv();
|
||||
template <bool rec> extern void ppc_fadds();
|
||||
template <bool rec> extern void ppc_fsubs();
|
||||
template <bool rec> extern void ppc_fmuls();
|
||||
template <bool rec> extern void ppc_fdivs();
|
||||
template <bool rec> extern void ppc_fmadd();
|
||||
template <bool rec> extern void ppc_fmsub();
|
||||
template <bool rec> extern void ppc_fnmadd();
|
||||
template <bool rec> extern void ppc_fnmsub();
|
||||
template <bool rec> extern void ppc_fmadds();
|
||||
template <bool rec> extern void ppc_fmsubs();
|
||||
template <bool rec> extern void ppc_fnmadds();
|
||||
template <bool rec> extern void ppc_fnmsubs();
|
||||
template <bool rec> extern void ppc_fabs();
|
||||
template <bool rec> extern void ppc_fnabs();
|
||||
template <bool rec> extern void ppc_fneg();
|
||||
template <bool rec> extern void ppc_fsel();
|
||||
template <bool rec> extern void ppc_fres();
|
||||
template <bool rec> extern void ppc_fsqrts();
|
||||
template <bool rec> extern void ppc_fsqrt();
|
||||
template <bool rec> extern void ppc_frsqrte();
|
||||
template <bool rec> extern void ppc_frsp();
|
||||
template <bool rec> extern void ppc_fctiw();
|
||||
template <bool rec> extern void ppc_fctiwz();
|
||||
template <field_rc rec> extern void ppc_fadd(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsub(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmul(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fdiv(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fadds(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsubs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmuls(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fdivs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmadd(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmsub(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmadd(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmsub(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmadds(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fmsubs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmadds(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnmsubs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fabs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fnabs(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fneg(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsel(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fres(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsqrts(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fsqrt(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_frsqrte(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_frsp(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fctiw(uint32_t opcode);
|
||||
template <field_rc rec> extern void ppc_fctiwz(uint32_t opcode);
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
extern void ppc_fcmpo(uint32_t opcode);
|
||||
extern void ppc_fcmpu(uint32_t opcode);
|
||||
|
||||
// Power-specific instructions
|
||||
template <bool rec, bool ov> extern void power_abs();
|
||||
extern void power_clcs();
|
||||
template <bool rec, bool ov> extern void power_div();
|
||||
template <bool rec, bool ov> extern void power_divs();
|
||||
template <bool rec, bool ov> extern void power_doz();
|
||||
extern void power_dozi();
|
||||
template <bool rec> extern void power_lscbx();
|
||||
template <bool rec> extern void power_maskg();
|
||||
template <bool rec> extern void power_maskir();
|
||||
template <bool rec, bool ov> extern void power_mul();
|
||||
template <bool rec, bool ov> extern void power_nabs();
|
||||
extern void power_rlmi();
|
||||
template <bool rec> extern void power_rrib();
|
||||
template <bool rec> extern void power_sle();
|
||||
template <bool rec> extern void power_sleq();
|
||||
template <bool rec> extern void power_sliq();
|
||||
template <bool rec> extern void power_slliq();
|
||||
template <bool rec> extern void power_sllq();
|
||||
template <bool rec> extern void power_slq();
|
||||
template <bool rec> extern void power_sraiq();
|
||||
template <bool rec> extern void power_sraq();
|
||||
template <bool rec> extern void power_sre();
|
||||
template <bool rec> extern void power_srea();
|
||||
template <bool rec> extern void power_sreq();
|
||||
template <bool rec> extern void power_sriq();
|
||||
template <bool rec> extern void power_srliq();
|
||||
template <bool rec> extern void power_srlq();
|
||||
template <bool rec> extern void power_srq();
|
||||
template <field_rc rec, field_ov ov> extern void power_abs(uint32_t opcode);
|
||||
extern void power_clcs(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_div(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_divs(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_doz(uint32_t opcode);
|
||||
extern void power_dozi(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_lscbx(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_maskg(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_maskir(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_mul(uint32_t opcode);
|
||||
template <field_rc rec, field_ov ov> extern void power_nabs(uint32_t opcode);
|
||||
extern void power_rlmi(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_rrib(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sle(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sleq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sliq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_slliq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sllq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_slq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sraiq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sraq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sre(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srea(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sreq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_sriq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srliq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srlq(uint32_t opcode);
|
||||
template <field_rc rec> extern void power_srq(uint32_t opcode);
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
@@ -625,14 +675,16 @@ template <bool rec> extern void power_srq();
|
||||
|
||||
extern uint64_t get_virt_time_ns(void);
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_main_opcode(PPCOpcode* ppc_opcode_grabber, uint32_t opcode);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
|
||||
|
||||
extern PPCOpcode* ppc_opcode_grabber;
|
||||
extern void ppc_msr_did_change(uint32_t old_msr_val, uint32_t new_msr_val, bool set_next_instruction_address = true);
|
||||
|
||||
/* debugging support API */
|
||||
void print_fprs(void); /* print content of the floating-point registers */
|
||||
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
|
||||
|
||||
|
||||
+37
-31
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
@@ -56,7 +57,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ISI:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
|
||||
@@ -65,7 +66,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
@@ -89,7 +90,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
if (exec_flags & ~EXEF_OPC_DECODER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
|
||||
@@ -113,9 +114,14 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
}
|
||||
|
||||
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 & ~MSR::LE) | !!(ppc_state.msr & MSR::ILE);
|
||||
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 & MSR::IP) {
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
@@ -135,7 +141,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
std::string exc_descriptor;
|
||||
@@ -195,17 +201,17 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception() {
|
||||
void ppc_floating_point_exception(uint32_t opcode) {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, ppc_cur_instruction);
|
||||
ppc_state.pc, opcode);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t ea)
|
||||
void ppc_alignment_exception(uint32_t opcode, uint32_t ea)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (ppc_cur_instruction & 0xfc000000) {
|
||||
switch (opcode & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
@@ -226,12 +232,12 @@ void ppc_alignment_exception(uint32_t ea)
|
||||
case 0xcc000000: // lfdu
|
||||
case 0xd4000000: // stfsu
|
||||
case 0xdc000000: // stfdu
|
||||
indirect_with_immediate_index:
|
||||
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
// indirect with immediate index
|
||||
dsisr = ((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 (ppc_cur_instruction & 0xfc0007ff) {
|
||||
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
|
||||
@@ -265,12 +271,12 @@ indirect_with_immediate_index:
|
||||
case 0x7c00056e: // stfsux
|
||||
case 0x7c0005ee: // stfdux
|
||||
indirect_with_index:
|
||||
dsisr = ((ppc_cur_instruction << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((ppc_cur_instruction << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((ppc_cur_instruction << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
dsisr = ((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 ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
if ((opcode & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
@@ -281,31 +287,31 @@ indirect_with_index:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
ppc_cur_instruction);
|
||||
opcode);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
|
||||
dsisr |= ((opcode >> 16) & 0x000003e0);
|
||||
|
||||
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
|
||||
if ((opcode & 0xfc000000) == 0xb8000000) { // lmw
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
else if ((opcode & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
else if ((opcode & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
"What to set DSISR bits 27-31?", opcode);
|
||||
// dsisr |= ((opcode >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
|
||||
dsisr |= ((opcode >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
|
||||
+608
-720
File diff suppressed because it is too large.
Load diff
+842
-511
File diff suppressed because it is too large.
Load diff
+65
-24
@@ -36,48 +36,92 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
# define ppc_grab_regsasimm(opcode) \
|
||||
#define ppc_grab_regsasimm(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int32_t simm = int32_t(int16_t(opcode)); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
# define ppc_grab_regssauimm(opcode) \
|
||||
#define ppc_grab_regssauimm(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfd_regsauimm(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_da(opcode)\
|
||||
int reg_d = (opcode >> 21) & 31;\
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
|
||||
#define ppc_grab_dab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define ppc_grab_s(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s];
|
||||
|
||||
#define ppc_grab_regsdab(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
int reg_b = (opcode >> 11) & 31;\
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssa_stmw(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
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) \
|
||||
uint32_t reg_s = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
@@ -94,27 +138,24 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result;
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_sfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
#define ppc_store_fpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_sfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
|
||||
#define ppc_store_dfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
|
||||
#define ppc_store_dfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
#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) \
|
||||
#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; \
|
||||
@@ -169,4 +210,4 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
#endif // PPC_MACROS_H
|
||||
+196
-597
File diff suppressed because it is too large.
Load diff
+9
-21
@@ -81,12 +81,12 @@ typedef struct MapDmaResult {
|
||||
uint32_t dev_base;
|
||||
} MapDmaResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define PAGE_SIZE (1 << PAGE_SIZE_BITS)
|
||||
#define PAGE_MASK ~(PAGE_SIZE - 1)
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
constexpr uint32_t PPC_PAGE_SIZE_BITS = 12;
|
||||
constexpr uint32_t PPC_PAGE_SIZE = (1 << PPC_PAGE_SIZE_BITS);
|
||||
constexpr uint32_t PPC_PAGE_MASK = ~(PPC_PAGE_SIZE - 1);
|
||||
constexpr uint32_t TLB_SIZE = 4096;
|
||||
constexpr uint32_t TLB2_WAYS = 4;
|
||||
constexpr uint32_t TLB_INVALID_TAG = 0xFFFFFFFF;
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
@@ -126,25 +126,13 @@ extern void mmu_pat_ctx_changed();
|
||||
extern void tlb_flush_entry(uint32_t ea);
|
||||
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
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);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
extern T mmu_read_vmem(uint32_t opcode, uint32_t guest_va);
|
||||
template <class T>
|
||||
extern void mmu_write_vmem(uint32_t guest_va, T value);
|
||||
|
||||
//====================== Deprecated calls =========================
|
||||
#if 0
|
||||
extern void mem_write_byte(uint32_t addr, uint8_t value);
|
||||
extern void mem_write_word(uint32_t addr, uint16_t value);
|
||||
extern void mem_write_dword(uint32_t addr, uint32_t value);
|
||||
extern void mem_write_qword(uint32_t addr, uint64_t value);
|
||||
extern uint8_t mem_grab_byte(uint32_t addr);
|
||||
extern uint16_t mem_grab_word(uint32_t addr);
|
||||
extern uint32_t mem_grab_dword(uint32_t addr);
|
||||
extern uint64_t mem_grab_qword(uint32_t addr);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
extern void mmu_write_vmem(uint32_t opcode, uint32_t guest_va, T value);
|
||||
|
||||
#endif // PPCMMU_H
|
||||
+787
-664
File diff suppressed because it is too large.
Load diff
@@ -313,6 +313,10 @@ def gen_rot_opcode(opc_str, sh, mb, me):
|
||||
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1)
|
||||
elif opc_str == "RLWINM.":
|
||||
return (0x15 << 26) + (4 << 21) + (3 << 16) + (sh << 11) + (mb << 6) + (me << 1) + 1
|
||||
elif opc_str == "RLWNM":
|
||||
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1)
|
||||
elif opc_str == "RLWNM.":
|
||||
return (0x17 << 26) + (4 << 21) + (3 << 16) + (3 << 11) + (mb << 6) + (me << 1) + 1
|
||||
|
||||
def extract_imm(line):
|
||||
pos = 12
|
||||
|
||||
+26
-20
@@ -36,12 +36,17 @@ using namespace std;
|
||||
int ntested; // number of tested instructions
|
||||
int nfailed; // number of failed instructions
|
||||
|
||||
#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;
|
||||
nfailed++;
|
||||
@@ -113,7 +118,7 @@ static void read_test_data() {
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
dest = 0;
|
||||
src1 = 0;
|
||||
@@ -123,15 +128,15 @@ static void read_test_data() {
|
||||
|
||||
for (i = 2; i < tokens.size(); i++) {
|
||||
if (tokens[i].rfind("rD=", 0) == 0) {
|
||||
dest = stoul(tokens[i].substr(3), NULL, 16);
|
||||
dest = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("rA=", 0) == 0) {
|
||||
src1 = stoul(tokens[i].substr(3), NULL, 16);
|
||||
src1 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("rB=", 0) == 0) {
|
||||
src2 = stoul(tokens[i].substr(3), NULL, 16);
|
||||
src2 = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else if (tokens[i].rfind("XER=", 0) == 0) {
|
||||
check_xer = stoul(tokens[i].substr(4), NULL, 16);
|
||||
check_xer = (uint32_t)stoul(tokens[i].substr(4), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
@@ -145,9 +150,7 @@ static void read_test_data() {
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
@@ -227,7 +230,7 @@ static void read_test_float_data() {
|
||||
continue;
|
||||
}
|
||||
|
||||
opcode = stoul(tokens[1], NULL, 16);
|
||||
opcode = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
src1 = 0;
|
||||
src2 = 0;
|
||||
@@ -253,9 +256,9 @@ static void read_test_float_data() {
|
||||
} else if (tokens[i].rfind("round=", 0) == 0) {
|
||||
rounding_mode = tokens[i].substr(6, 3);
|
||||
} else if (tokens[i].rfind("FPSCR=", 0) == 0) {
|
||||
check_fpscr = stoul(tokens[i].substr(6), NULL, 16);
|
||||
check_fpscr = (uint32_t)stoul(tokens[i].substr(6), NULL, 16);
|
||||
} else if (tokens[i].rfind("CR=", 0) == 0) {
|
||||
check_cr = stoul(tokens[i].substr(3), NULL, 16);
|
||||
check_cr = (uint32_t)stoul(tokens[i].substr(3), NULL, 16);
|
||||
} else {
|
||||
cout << "Unknown parameter " << tokens[i] << " in line " << lineno << ". Exiting..."
|
||||
<< endl;
|
||||
@@ -289,9 +292,7 @@ static void read_test_float_data() {
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(ppc_opcode_grabber, opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
@@ -301,10 +302,11 @@ static void read_test_float_data() {
|
||||
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 << "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;
|
||||
<< 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;
|
||||
@@ -315,7 +317,11 @@ static void read_test_float_data() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
initialize_ppc_opcode_tables(); //kludge
|
||||
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;
|
||||
|
||||
|
||||
@@ -65,15 +65,15 @@ static vector<PPCDisasmContext> read_test_data() {
|
||||
}
|
||||
|
||||
ctx = {0};
|
||||
ctx.instr_addr = stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = stoul(tokens[1], NULL, 16);
|
||||
ctx.instr_addr = (uint32_t)stoul(tokens[0], NULL, 16);
|
||||
ctx.instr_code = (uint32_t)stoul(tokens[1], NULL, 16);
|
||||
|
||||
/* build disassembly string out of comma-separated parts */
|
||||
ostringstream idisasm;
|
||||
|
||||
/* put instruction mnemonic padded with trailing spaces */
|
||||
idisasm << tokens[2];
|
||||
idisasm << setw(8 - tokens[2].length()) << "";
|
||||
idisasm << setw(streamsize(8) - (int)tokens[2].length()) << " ";
|
||||
|
||||
/* now add comma-separated operands */
|
||||
for (i = 3; i < tokens.size(); i++) {
|
||||
|
||||
@@ -2,6 +2,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+247
-78
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cpu/ppc/ppcdisasm.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <debugger/debugger.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include "memaccess.h"
|
||||
@@ -50,9 +51,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define COUTX uppercase << hex
|
||||
#define COUT0_X(w) setfill('0') << setw(w) << right << COUTX
|
||||
#define COUT016X COUT0_X(16)
|
||||
#define COUT08X COUT0_X(8)
|
||||
#define COUT04X COUT0_X(4)
|
||||
|
||||
static uint32_t str2addr(string& addr_str) {
|
||||
try {
|
||||
return (uint32_t)stoul(addr_str, NULL, 0);
|
||||
return static_cast<uint32_t>(stoul(addr_str, NULL, 0));
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + addr_str);
|
||||
}
|
||||
@@ -60,7 +67,7 @@ static uint32_t str2addr(string& addr_str) {
|
||||
|
||||
static uint32_t str2num(string& num_str) {
|
||||
try {
|
||||
return (uint32_t)stol(num_str, NULL, 0);
|
||||
return static_cast<uint32_t>(stol(num_str, NULL, 0));
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
@@ -68,41 +75,49 @@ static uint32_t str2num(string& num_str) {
|
||||
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " go -- exit debugger and continue emulator execution" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " mregs -- dump content of the MMU registers" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " profile C N -- run subcommand C on profile N" << endl;
|
||||
cout << " supported subcommands:" << endl;
|
||||
cout << " 'show' - show profile report" << endl;
|
||||
cout << " 'reset' - reset profile variables" << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " go -- exit debugger and continue emulator execution" << endl;
|
||||
cout << " regs -- dump content of the GPRs" << endl;
|
||||
cout << " fregs -- dump content of the FPRs" << endl;
|
||||
cout << " mregs -- dump content of the MMU registers" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " setmem X=V.T -- set memory at address X to value V of size T" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " regions -- dump memory regions" << endl;
|
||||
cout << " profile C N -- run subcommand C on profile N" << endl;
|
||||
cout << " supported subcommands:" << endl;
|
||||
cout << " 'show' - show profile report" << endl;
|
||||
cout << " 'reset' - reset profile variables" << endl;
|
||||
#ifdef PROFILER
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
#endif
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " da N,X -- shortcut for disas" << endl;
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
cout << " da N,X -- shortcut for disas" << endl;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
#endif
|
||||
cout << " printenv -- print current NVRAM settings." << endl;
|
||||
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << " printenv -- print current NVRAM settings." << endl;
|
||||
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
|
||||
cout << endl;
|
||||
cout << " restart -- restart the machine" << endl;
|
||||
cout << " quit -- quit the debugger" << endl;
|
||||
cout << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
@@ -110,7 +125,7 @@ static void show_help() {
|
||||
|
||||
static uint32_t disasm_68k(uint32_t count, uint32_t address) {
|
||||
csh cs_handle;
|
||||
uint8_t code[10];
|
||||
uint8_t code[12]{};
|
||||
size_t code_size;
|
||||
uint64_t dis_addr;
|
||||
|
||||
@@ -122,9 +137,14 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
|
||||
cs_insn* insn = cs_malloc(cs_handle);
|
||||
|
||||
for (; power_on && count > 0; count--) {
|
||||
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
|
||||
// prefetch opcode bytes (a 68k instruction can occupy 2...12 bytes)
|
||||
for (int i = 0; i < sizeof(code); i++) {
|
||||
code[i] = mem_read_dbg(address + i, 1);
|
||||
try {
|
||||
code[i] = mem_read_dbg(address + i, 1);
|
||||
}
|
||||
catch(...) {
|
||||
printf("<memerror>");
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t *code_ptr = code;
|
||||
@@ -138,16 +158,16 @@ static uint32_t disasm_68k(uint32_t count, uint32_t address) {
|
||||
}
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << COUTX << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << right << endl;
|
||||
address = static_cast<uint32_t>(dis_addr);
|
||||
} else {
|
||||
print_bin:
|
||||
cout << uppercase << hex << address << " ";
|
||||
cout << COUTX << address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << "dc.w" << "$" << hex <<
|
||||
((code[0] << 8) | code[1]) << endl;
|
||||
((code[0] << 8) | code[1]) << right << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
@@ -158,7 +178,7 @@ print_bin:
|
||||
}
|
||||
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
constexpr auto EMU_68K_TABLE_SIZE = 0x80000;
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
@@ -167,17 +187,17 @@ void exec_single_68k()
|
||||
|
||||
/* PPC r24 contains 68k PC advanced by two bytes
|
||||
as part of instruction prefetching */
|
||||
cur_68k_pc = get_reg(string("R24")) - 2;
|
||||
cur_68k_pc = static_cast<uint32_t>(get_reg(string("R24")) - 2);
|
||||
|
||||
/* PPC r29 contains base address of the emulator opcode table */
|
||||
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(NO_OPCODE, cur_68k_pc) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
|
||||
|
||||
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
|
||||
|
||||
@@ -186,7 +206,7 @@ void exec_single_68k()
|
||||
one by one until the execution goes outside the opcode table. */
|
||||
while (power_on && ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
|
||||
ppc_exec_single();
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
ppc_pc = static_cast<uint32_t>(get_reg(string("PC")));
|
||||
}
|
||||
|
||||
/* Getting here means we're outside the emualtor opcode table.
|
||||
@@ -219,21 +239,22 @@ void print_68k_regs()
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
reg = "R" + to_string(i + 8);
|
||||
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
cout << " D" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
for (i = 0; i < 7; i++) {
|
||||
reg = "R" + to_string(i + 16);
|
||||
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
cout << " A" << dec << i << " : " << COUT08X << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
|
||||
cout << " A7 : " << COUT08X << get_reg(string("R1")) << endl;
|
||||
|
||||
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
|
||||
cout << " PC : " << COUT08X << get_reg(string("R24")) - 2 << endl;
|
||||
|
||||
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
|
||||
cout << " SR : " << COUT08X << ((get_reg("R25") & 0xFF) << 8) << endl;
|
||||
|
||||
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
|
||||
cout << " CCR : " << COUT08X << get_reg(string("R26")) << endl;
|
||||
cout << dec << setfill(' ');
|
||||
}
|
||||
|
||||
#endif // ENABLE_68K_DEBUGGER
|
||||
@@ -319,8 +340,7 @@ static void dump_mem(string& params) {
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
cout << COUT0_X(cell_size * 2) << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
@@ -332,6 +352,79 @@ static void dump_mem(string& params) {
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
static void patch_mem(string& params) {
|
||||
int value_size = 1;
|
||||
uint32_t addr, value;
|
||||
string addr_str, value_str, size_str;
|
||||
|
||||
if (params.find_first_of("=") == std::string::npos) {
|
||||
cout << "setmem: not enough arguments specified. Try 'help'." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
addr_str = params.substr(0, params.find_first_of("="));
|
||||
value_str = params.substr(params.find_first_of("=") + 1);
|
||||
|
||||
if (value_str.find_first_of(".") == std::string::npos) {
|
||||
cout << "setmem: no value size specified. Try 'help'." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
size_str = value_str.substr(value_str.find_first_of(".") + 1);
|
||||
value_str = value_str.substr(0, value_str.find_first_of("."));
|
||||
|
||||
switch (size_str.back()) {
|
||||
case 'b':
|
||||
case 'B':
|
||||
value_size = 1;
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
value_size = 2;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
value_size = 4;
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
value_size = 8;
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
value_size = 1;
|
||||
break;
|
||||
default:
|
||||
cout << "Invalid value size " << size_str << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
// number conversion failed, trying reg name
|
||||
addr = get_reg(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
value = str2num(value_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mem_write_dbg(addr, value, value_size);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
@@ -340,9 +433,9 @@ static uint32_t disasm(uint32_t count, uint32_t address) {
|
||||
|
||||
for (int i = 0; power_on && i < count; i++) {
|
||||
ctx.instr_code = READ_DWORD_BE_A(mmu_translate_imem(ctx.instr_addr));
|
||||
cout << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_addr;
|
||||
cout << ": " << setfill('0') << setw(8) << right << uppercase << hex << ctx.instr_code;
|
||||
cout << " " << disassemble_single(&ctx) << setfill(' ') << left << endl;
|
||||
cout << COUT08X << ctx.instr_addr;
|
||||
cout << ": " << COUT08X << ctx.instr_code;
|
||||
cout << " " << disassemble_single(&ctx) << setfill(' ') << right << endl;
|
||||
}
|
||||
return ctx.instr_addr;
|
||||
}
|
||||
@@ -352,10 +445,10 @@ static void print_gprs() {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
reg_name = "R" + to_string(i);
|
||||
reg_name = "r" + to_string(i);
|
||||
|
||||
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
|
||||
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name) << setfill(' ');
|
||||
cout << right << std::setw(5) << setfill(' ') << reg_name << " : " <<
|
||||
COUT08X << get_reg(reg_name) << setfill(' ');
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
@@ -364,11 +457,11 @@ static void print_gprs() {
|
||||
}
|
||||
}
|
||||
|
||||
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
|
||||
array<string, 8> sprs = {"pc", "lr", "cr", "ctr", "xer", "msr", "srr0", "srr1"};
|
||||
|
||||
for (auto &spr : sprs) {
|
||||
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
|
||||
setw(8) << setfill('0') << uppercase << hex << get_reg(spr) << setfill(' ');
|
||||
cout << right << std::setw(5) << setfill(' ') << spr << " : " <<
|
||||
COUT08X << get_reg(spr) << setfill(' ');
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
@@ -380,34 +473,46 @@ static void print_gprs() {
|
||||
}
|
||||
}
|
||||
|
||||
static void print_fprs() {
|
||||
string reg_name;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
reg_name = "f" + to_string(i);
|
||||
cout << right << std::setw(6) << setfill(' ') << reg_name << " : " <<
|
||||
COUT016X << ppc_state.fpr[i].int64_r <<
|
||||
" = " << left << setfill(' ') << ppc_state.fpr[i].dbl64_r << endl;
|
||||
}
|
||||
cout << right << std::setw(6) << setfill(' ') << "fpscr" << " : " <<
|
||||
COUT08X << ppc_state.fpscr << setfill(' ') << endl;
|
||||
}
|
||||
|
||||
extern bool is_601;
|
||||
|
||||
static void print_mmu_regs()
|
||||
{
|
||||
printf("MSR : 0x%08X\n", ppc_state.msr);
|
||||
printf(" msr : %08X\n", ppc_state.msr);
|
||||
|
||||
printf("\nBAT registers:\n");
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("IBAT%dU : 0x%08X, IBAT%dL : 0x%08X\n",
|
||||
printf(" ibat%du : %08X ibat%dl : %08X\n",
|
||||
i, ppc_state.spr[528+i*2],
|
||||
i, ppc_state.spr[529+i*2]);
|
||||
}
|
||||
|
||||
if (!is_601) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("DBAT%dU : 0x%08X, DBAT%dL : 0x%08X\n",
|
||||
printf(" dbat%du : %08X dbat%dl : %08X\n",
|
||||
i, ppc_state.spr[536+i*2],
|
||||
i, ppc_state.spr[537+i*2]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("SDR1 : 0x%08X\n", ppc_state.spr[SPR::SDR1]);
|
||||
printf(" sdr1 : %08X\n", ppc_state.spr[SPR::SDR1]);
|
||||
printf("\nSegment registers:\n");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
printf("SR%-2d : 0x%08X\n", i, ppc_state.sr[i]);
|
||||
printf(" %ssr%d : %08X\n", (i < 10) ? " " : "", i, ppc_state.sr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,7 +543,18 @@ static void mysig_handler(int signum)
|
||||
}
|
||||
#endif
|
||||
|
||||
void enter_debugger() {
|
||||
static void delete_prompt() {
|
||||
#ifndef _WIN32
|
||||
// move up, carriage return (move to column 0), erase from cursor to end of line
|
||||
cout << "\e[A\r\e[0K";
|
||||
#endif
|
||||
}
|
||||
|
||||
DppcDebugger::DppcDebugger() {
|
||||
|
||||
}
|
||||
|
||||
void DppcDebugger::enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
|
||||
inst_string, inst_num_str, profile_name, sub_cmd;
|
||||
uint32_t addr, inst_grab;
|
||||
@@ -447,8 +563,11 @@ void enter_debugger() {
|
||||
size_t separator_pos;
|
||||
bool did_message = false;
|
||||
uint32_t next_addr_ppc;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
uint32_t next_addr_68k;
|
||||
#endif
|
||||
bool cmd_repeat;
|
||||
int repeat_count = 0;
|
||||
|
||||
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
|
||||
|
||||
@@ -456,7 +575,7 @@ void enter_debugger() {
|
||||
|
||||
#ifndef _WIN32
|
||||
struct winsize win_size_previous;
|
||||
ioctl(0, TIOCGWINSZ, &win_size_previous);
|
||||
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_previous);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
@@ -468,6 +587,10 @@ void enter_debugger() {
|
||||
power_off_reason = po_restarting;
|
||||
break;
|
||||
}
|
||||
if (power_off_reason == po_quit) {
|
||||
power_off_reason = po_quitting;
|
||||
break;
|
||||
}
|
||||
power_on = true;
|
||||
|
||||
if (power_off_reason == po_starting_up) {
|
||||
@@ -491,6 +614,7 @@ void enter_debugger() {
|
||||
power_off_reason = po_entered_debugger;
|
||||
}
|
||||
if (!did_message) {
|
||||
cout << endl;
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
cout << "Please enter a command or 'help'." << endl << endl;
|
||||
did_message = true;
|
||||
@@ -511,7 +635,7 @@ void enter_debugger() {
|
||||
|
||||
#ifndef _WIN32
|
||||
struct winsize win_size_current;
|
||||
ioctl(0, TIOCGWINSZ, &win_size_current);
|
||||
ioctl(STDIN_FILENO, TIOCGWINSZ, &win_size_current);
|
||||
if (win_size_current.ws_col != win_size_previous.ws_col || win_size_current.ws_row != win_size_previous.ws_row) {
|
||||
win_size_previous = win_size_current;
|
||||
if (cmd.empty()) {
|
||||
@@ -530,9 +654,18 @@ void enter_debugger() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feof(stdin)) {
|
||||
printf("eof -> quit\n");
|
||||
cmd = "quit";
|
||||
}
|
||||
|
||||
cmd_repeat = cmd.empty() && !last_cmd.empty();
|
||||
if (cmd_repeat) {
|
||||
cmd = last_cmd;
|
||||
repeat_count++;
|
||||
}
|
||||
else {
|
||||
repeat_count = 1;
|
||||
}
|
||||
if (cmd == "help") {
|
||||
cmd = "";
|
||||
@@ -540,6 +673,10 @@ void enter_debugger() {
|
||||
} else if (cmd == "quit") {
|
||||
cmd = "";
|
||||
break;
|
||||
} else if (cmd == "restart") {
|
||||
cmd = "";
|
||||
power_on = false;
|
||||
power_off_reason = po_restart;
|
||||
} else if (cmd == "profile") {
|
||||
cmd = "";
|
||||
ss >> sub_cmd;
|
||||
@@ -562,6 +699,9 @@ void enter_debugger() {
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
} else if (cmd == "fregs") {
|
||||
cmd = "";
|
||||
print_fprs();
|
||||
} else if (cmd == "mregs") {
|
||||
cmd = "";
|
||||
print_mmu_regs();
|
||||
@@ -609,21 +749,34 @@ void enter_debugger() {
|
||||
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
if (cmd_repeat) {
|
||||
delete_prompt();
|
||||
}
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
if (cmd_repeat) {
|
||||
delete_prompt();
|
||||
}
|
||||
for (; --count >= 0;) {
|
||||
addr = ppc_state.pc;
|
||||
ppc_exec_single();
|
||||
}
|
||||
}
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = (uint32_t)get_reg(addr_str) + 4;
|
||||
addr = static_cast<uint32_t>(get_reg(addr_str) + 4);
|
||||
ppc_exec_until(addr);
|
||||
} else if (cmd == "until") {
|
||||
ss >> addr_str;
|
||||
if (cmd_repeat) {
|
||||
delete_prompt();
|
||||
cout << repeat_count << "> " << cmd << " " << addr_str << endl;
|
||||
}
|
||||
else {
|
||||
ss >> addr_str;
|
||||
}
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
if (context == 2) {
|
||||
@@ -692,21 +845,23 @@ void enter_debugger() {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
if (cmd_repeat) {
|
||||
delete_prompt();
|
||||
addr = next_addr_68k;
|
||||
}
|
||||
else {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
addr = static_cast<uint32_t>(get_reg(addr_str) - 2);
|
||||
}
|
||||
next_addr_68k = disasm_68k(1, addr);
|
||||
#endif
|
||||
} else {
|
||||
if (cmd_repeat) {
|
||||
delete_prompt();
|
||||
addr = next_addr_ppc;
|
||||
}
|
||||
else {
|
||||
addr_str = "PC";
|
||||
addr = (uint32_t)get_reg(addr_str);
|
||||
addr = static_cast<uint32_t>(get_reg(addr_str));
|
||||
}
|
||||
next_addr_ppc = disasm(1, addr);
|
||||
}
|
||||
@@ -718,6 +873,10 @@ void enter_debugger() {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
dump_mem(expr_str);
|
||||
} else if (cmd == "setmem") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
patch_mem(expr_str);
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
} else if (cmd == "context") {
|
||||
cmd = "";
|
||||
@@ -731,6 +890,10 @@ void enter_debugger() {
|
||||
cout << "Unknown debugging context: " << expr_str << endl;
|
||||
}
|
||||
#endif
|
||||
} else if (cmd == "regions") {
|
||||
cmd = "";
|
||||
if (mem_ctrl_instance)
|
||||
mem_ctrl_instance->dump_regions();
|
||||
} else if (cmd == "printenv") {
|
||||
cmd = "";
|
||||
if (ofnvram->init())
|
||||
@@ -742,9 +905,15 @@ void enter_debugger() {
|
||||
ss >> var_name;
|
||||
std::istream::sentry se(ss); // skip white space
|
||||
getline(ss, value); // get everything up to eol
|
||||
if (ofnvram->init())
|
||||
if (ofnvram->init()) {
|
||||
cout << " Cannot open NVRAM" << endl;
|
||||
continue;
|
||||
ofnvram->setenv(var_name, value);
|
||||
}
|
||||
if (!ofnvram->setenv(var_name, value)) {
|
||||
cout << " Please try again" << endl;
|
||||
} else {
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
}
|
||||
#ifndef _WIN32
|
||||
} else if (cmd == "nvedit") {
|
||||
cmd = "";
|
||||
|
||||
+17
-1
@@ -22,6 +22,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef DEBUGGER_H_
|
||||
#define DEBUGGER_H_
|
||||
|
||||
void enter_debugger();
|
||||
#include <memory>
|
||||
|
||||
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_
|
||||
@@ -8,10 +8,14 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
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/firewire/*.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}/common/usb/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
|
||||
|
||||
@@ -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
|
||||
@@ -25,6 +25,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#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);
|
||||
@@ -32,6 +34,30 @@ AdbBus::AdbBus(std::string name) {
|
||||
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);
|
||||
}
|
||||
@@ -102,8 +128,12 @@ uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
|
||||
return ADB_STAT_OK;
|
||||
}
|
||||
|
||||
static const PropMap AdbBus_Properties = {
|
||||
{"adb_devices", new StrProperty("Mouse,Keyboard")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AdbBus_Descriptor = {
|
||||
AdbBus::create, {}, {}
|
||||
AdbBus::create, {}, AdbBus_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
|
||||
@@ -30,7 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define ADB_MAX_DATA_SIZE 8
|
||||
constexpr auto ADB_MAX_DATA_SIZE = 8;
|
||||
|
||||
/** ADB status. */
|
||||
enum {
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
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; };
|
||||
|
||||
@@ -25,9 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <core/hostevents.h>
|
||||
#include <memaccess.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
|
||||
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();
|
||||
@@ -37,8 +41,14 @@ void AdbMouse::event_handler(const MouseEvent& event) {
|
||||
if (event.flags & MOUSE_EVENT_MOTION) {
|
||||
this->x_rel += event.xrel;
|
||||
this->y_rel += event.yrel;
|
||||
this->x_abs = event.xabs;
|
||||
this->y_abs = event.yabs;
|
||||
if (this->device_class == TABLET)
|
||||
this->changed = true;
|
||||
} else if (event.flags & MOUSE_EVENT_BUTTON) {
|
||||
this->buttons_state = event.buttons_state;
|
||||
this->buttons_state = event.buttons_state & ((1 << this->num_buttons) - 1);
|
||||
this->x_abs = event.xabs;
|
||||
this->y_abs = event.yabs;
|
||||
this->changed = true;
|
||||
}
|
||||
}
|
||||
@@ -50,44 +60,72 @@ void AdbMouse::reset() {
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->x_abs = 0;
|
||||
this->y_abs = 0;
|
||||
this->buttons_state = 0;
|
||||
this->changed = false;
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_0() {
|
||||
if (this->x_rel || this->y_rel || this->changed) {
|
||||
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();
|
||||
|
||||
uint8_t button1_state = (this->buttons_state ^ 1) << 7;
|
||||
static const uint8_t buttons_to_bits[] = {0, 7, 7, 10, 10, 13, 13, 16, 16};
|
||||
static const uint8_t bits_to_bits[] = {0, 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 13, 13, 13, 16, 16, 16};
|
||||
int 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;
|
||||
|
||||
// report Y-axis motion
|
||||
if (this->y_rel < -64)
|
||||
out_buf[0] = 0x40 | button1_state;
|
||||
else if (this->y_rel > 63)
|
||||
out_buf[0] = 0x3F | button1_state;
|
||||
else
|
||||
out_buf[0] = (this->y_rel & 0x7F) | button1_state;
|
||||
for (int axis = 0; axis < 2; axis++) {
|
||||
int bits = num_bits;
|
||||
int32_t val = axis ? this->device_class == TABLET ? this->x_abs : this->x_rel
|
||||
: this->device_class == TABLET ? this->y_abs : this->y_rel;
|
||||
if (val < (-1 << (bits - 1)))
|
||||
val = -1 << (bits - 1);
|
||||
else if (val >= (1 << (bits - 1)))
|
||||
val = (1 << (bits - 1)) - 1;
|
||||
int bits_remaining = total_bits;
|
||||
p = &out_buf[axis];
|
||||
int button = axis;
|
||||
bits = 7;
|
||||
|
||||
// report X-axis motion
|
||||
if (this->x_rel < -64)
|
||||
out_buf[1] = 0x40 | 0x80;
|
||||
else if (this->x_rel > 63)
|
||||
out_buf[1] = 0x3F | 0x80;
|
||||
else
|
||||
out_buf[1] = (this->x_rel & 0x7F) | 0x80;
|
||||
while (bits_remaining > 0) {
|
||||
*p = (val & ((1 << bits) - 1)) | (((buttons_state >> button) & 1) << bits) | (*p << (bits + 1));
|
||||
val >>= bits;
|
||||
bits_remaining -= bits;
|
||||
p = bits == 7 ? &out_buf[2] : p + 1;
|
||||
button += 2;
|
||||
bits = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// reset accumulated motion data and button change flag
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->changed = false;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
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
|
||||
@@ -96,10 +134,9 @@ bool AdbMouse::get_register_1() {
|
||||
out_buf[2] = 'p';
|
||||
out_buf[3] = 'l';
|
||||
// Slightly higher resolution of 300 units per inch
|
||||
out_buf[4] = 300 >> 8;
|
||||
out_buf[5] = 300 & 0xFF;
|
||||
out_buf[6] = 1; // mouse
|
||||
out_buf[7] = 1; // 1 button
|
||||
WRITE_WORD_BE_A(&out_buf[4], resolution);
|
||||
out_buf[6] = device_class;
|
||||
out_buf[7] = num_buttons;
|
||||
this->host_obj->set_output_count(8);
|
||||
return true;
|
||||
}
|
||||
@@ -130,6 +167,10 @@ void AdbMouse::set_register_3() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AdbMouse::get_buttons_state() const {
|
||||
return this->buttons_state;
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbMouse_Descriptor = {
|
||||
AdbMouse::create, {}, {}
|
||||
};
|
||||
|
||||
@@ -30,15 +30,36 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
//#define ABSOLUTE
|
||||
|
||||
class MouseEvent;
|
||||
|
||||
class AdbMouse : public AdbDevice {
|
||||
public:
|
||||
AdbMouse(std::string name);
|
||||
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() {
|
||||
return std::unique_ptr<AdbMouse>(new AdbMouse("ADB-MOUSE"));
|
||||
#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;
|
||||
@@ -48,11 +69,21 @@ public:
|
||||
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;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
int32_t x_abs = 0;
|
||||
int32_t y_abs = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
uint8_t device_class;
|
||||
int num_buttons;
|
||||
int num_bits;
|
||||
uint16_t resolution;
|
||||
};
|
||||
|
||||
#endif // ADB_MOUSE_H
|
||||
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <core/timermanager.h>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
@@ -46,6 +47,9 @@ void AtaBaseDevice::device_reset(bool is_soft_reset) {
|
||||
|
||||
// Diagnostic code
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
|
||||
// disable interrupts
|
||||
this->r_dev_ctrl |= ATA_CTRL::IEN;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_set_signature() {
|
||||
@@ -67,11 +71,13 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0)
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
else {
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
this->update_intrq(1);
|
||||
} else {
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(100), [this]() { this->update_intrq(1); });
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
@@ -104,20 +110,27 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (this->has_data()) {
|
||||
if (is_selected() && this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->post_xfer_action();
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0) { // transfer complete?
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
//LOG_F(INFO, "%s: write complete", name.c_str());
|
||||
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
});
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
this->signal_data_ready();
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
//LOG_F(INFO, "%s: write needs more data (left: 0x%x)", name.c_str(), xfer_cnt);
|
||||
TimerManager::get_instance()->add_oneshot_timer(USECS_TO_NSECS(100), [this]() {
|
||||
this->signal_data_ready();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +154,10 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
this->r_dev_head = value;
|
||||
break;
|
||||
case ATA_Reg::COMMAND:
|
||||
if ((this->r_status & BSY) != 0) {
|
||||
LOG_F(ERROR, "%s: tried to perform command %x when busy", name.c_str(), value);
|
||||
break;
|
||||
}
|
||||
this->r_command = value;
|
||||
if (is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
perform_command();
|
||||
|
||||
@@ -40,14 +40,17 @@ public:
|
||||
AtaBaseDevice(const std::string name, uint8_t type);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
void set_host(IdeChannel* host) { this->host_obj = host; };
|
||||
void set_host(IdeChannel* host, uint8_t dev_id) {
|
||||
this->host_obj = host;
|
||||
this->my_dev_id = dev_id;
|
||||
};
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
int get_device_id() override { return this->my_dev_id; };
|
||||
int get_device_id() override { return this->my_dev_id; }
|
||||
|
||||
void pdiag_callback() override {
|
||||
this->r_error &= 0x7F;
|
||||
@@ -59,7 +62,7 @@ public:
|
||||
void update_intrq(uint8_t new_intrq_state);
|
||||
void signal_data_ready();
|
||||
|
||||
bool has_data() {
|
||||
bool has_data() const {
|
||||
return data_ptr && xfer_cnt;
|
||||
}
|
||||
|
||||
@@ -68,7 +71,9 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
|
||||
bool is_selected() const {
|
||||
return ((this->r_dev_head >> 4) & 1) == this->my_dev_id;
|
||||
}
|
||||
|
||||
void prepare_xfer(int xfer_size, int block_size);
|
||||
|
||||
@@ -79,7 +84,7 @@ protected:
|
||||
IdeChannel* host_obj = nullptr;
|
||||
|
||||
// IDE aka task file registers
|
||||
uint8_t r_error;
|
||||
uint8_t r_error = 0;
|
||||
uint8_t r_features;
|
||||
uint8_t r_sect_count;
|
||||
uint8_t r_sect_num;
|
||||
@@ -89,10 +94,11 @@ protected:
|
||||
uint8_t r_command;
|
||||
uint8_t r_status;
|
||||
uint8_t r_status_save;
|
||||
uint8_t r_dev_ctrl = 0x08;
|
||||
uint8_t r_dev_ctrl = 0x08 | ata_interface::ATA_CTRL::IEN; // disable interrupts
|
||||
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint16_t *cur_data_ptr = nullptr;
|
||||
alignas(uint16_t)
|
||||
uint8_t data_buf[512] = {};
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
|
||||
@@ -117,33 +117,38 @@ enum ATA_CTRL : uint8_t {
|
||||
|
||||
/* ATA commands. */
|
||||
enum ATA_Cmd : uint8_t {
|
||||
NOP = 0x00,
|
||||
ATAPI_SOFT_RESET = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
READ_SECTOR = 0x20,
|
||||
READ_SECTOR_NR = 0x21,
|
||||
READ_LONG = 0x22,
|
||||
READ_SECTOR_EXT = 0x24,
|
||||
WRITE_SECTOR = 0x30,
|
||||
WRITE_SECTOR_NR = 0x31,
|
||||
WRITE_LONG = 0x32,
|
||||
READ_VERIFY = 0x40,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
ATAPI_PACKET = 0xA0,
|
||||
ATAPI_IDFY_DEV = 0xA1,
|
||||
ATAPI_SERVICE = 0xA2,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
FLUSH_CACHE = 0xE7, // ATA-5
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
SET_FEATURES = 0xEF,
|
||||
NOP = 0x00,
|
||||
ATAPI_SOFT_RESET = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
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
|
||||
|
||||
+129
-52
@@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <bitset>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -44,6 +45,10 @@ int AtaHardDisk::device_postinit() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string hdd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (hdd_image_path.empty())
|
||||
return 0;
|
||||
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
|
||||
@@ -52,21 +57,24 @@ int AtaHardDisk::device_postinit() {
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
std::string hdd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (!hdd_image_path.empty()) {
|
||||
this->insert_image(hdd_image_path);
|
||||
}
|
||||
this->insert_image(hdd_image_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
if (!this->hdd_img.open(filename)) {
|
||||
ABORT_F("%s: could not open image file", this->name.c_str());
|
||||
ABORT_F("%s: could not open image file \"%s\"", this->name.c_str(),
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
this->img_size = this->hdd_img.size();
|
||||
this->total_sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
|
||||
uint64_t sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE;
|
||||
this->total_sectors = (uint32_t)sectors;
|
||||
if (sectors != this->total_sectors) {
|
||||
ABORT_F("%s: image file \"%s\" is too big", this->name.c_str(),
|
||||
filename.c_str());
|
||||
}
|
||||
this->calc_chs_params();
|
||||
}
|
||||
|
||||
@@ -77,38 +85,79 @@ int AtaHardDisk::perform_command() {
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
case ATAPI_SOFT_RESET: // for ATA devices, is a no-op
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case RECALIBRATE: // is optional in ATA-3; disappeared in >= ATA-4
|
||||
// OF 3.1.1 won't boot off the drive that reports error for this command
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_dev_head &= 0xF0;
|
||||
this->r_sect_num = (this->r_dev_head & ATA_Dev_Head::LBA) ? 0 : 1;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_MULTIPLE:
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
int xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == READ_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
hdd_img.read(buffer, offset, xfer_size);
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
// those commands should generate IRQ for each sector
|
||||
this->prepare_xfer(xfer_size, ATA_HD_SEC_SIZE);
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
break;
|
||||
case WRITE_MULTIPLE:
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->prepare_xfer(sec_count * ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
|
||||
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == WRITE_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, this->chunk_size);
|
||||
this->cur_fpos += this->chunk_size;
|
||||
uint64_t write_len = (this->cur_data_ptr - this->data_ptr) * sizeof(this->data_ptr[0]);
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, write_len);
|
||||
this->cur_fpos += write_len;
|
||||
};
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
}
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_VERIFY: // verify sectors are readable, just no-op
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
// update fictive disk geometry with parameters from host
|
||||
this->sectors = this->r_sect_count;
|
||||
@@ -116,9 +165,20 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1;
|
||||
this->device_set_signature();
|
||||
case SET_MULTIPLE_MODE: // this command is mandatory for ATA devices
|
||||
if (!this->r_sect_count || this->r_sect_count > SECTORS_PER_INT ||
|
||||
std::bitset<8>(this->r_sect_count).count() != 1) { // power of two?
|
||||
LOG_F(ERROR, "%s: invalid parameter %d for SET_MULTIPLE_MODE",
|
||||
this->name.c_str(), this->r_sect_count);
|
||||
this->r_error |= ABRT;
|
||||
this->r_status |= ERR;
|
||||
} else {
|
||||
LOG_F(9, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(),
|
||||
this->r_sect_count);
|
||||
this->sectors_per_int = this->r_sect_count;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case FLUSH_CACHE: // used by the XNU kernel driver
|
||||
this->r_status &= ~(BSY | DRQ | ERR);
|
||||
@@ -157,6 +217,11 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case STANDBY_IMMEDIATE_E0:
|
||||
LOG_F(INFO, "%s: STANDBY_IMMEDIATE_E0", this->name.c_str());
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unknown ATA command 0x%x", this->name.c_str(), this->r_command);
|
||||
this->r_status &= ~BSY;
|
||||
@@ -174,6 +239,16 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
buf_ptr[49] = 0x0200; // report LBA support
|
||||
|
||||
// Maximum number of logical sectors per data block that the device supports
|
||||
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
|
||||
|
||||
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
|
||||
// logical sectors that shall be transferred per data block for
|
||||
// READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
if (this->sectors_per_int)
|
||||
buf_ptr[59] = 0x100 | this->sectors_per_int;
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
@@ -204,57 +279,59 @@ uint64_t AtaHardDisk::get_lba() {
|
||||
}
|
||||
|
||||
void AtaHardDisk::calc_chs_params() {
|
||||
unsigned num_blocks, heads, sectors, max_sectors;
|
||||
unsigned num_blocks, heads, sectors, max_sectors, cylinders, max_cylinders;
|
||||
|
||||
LOG_F(INFO, "%s: total sectors %d", this->name.c_str(), this->total_sectors);
|
||||
|
||||
if (this->total_sectors >= REAL_CHS_LIMIT) {
|
||||
heads = 16;
|
||||
sectors = 255;
|
||||
cylinders = 65535;
|
||||
LOG_F(WARNING, "%s: exceeds max CHS translation",
|
||||
this->name.c_str());
|
||||
goto done;
|
||||
}
|
||||
|
||||
// use PC BIOS limit to keep number of sectors small for smaller disks
|
||||
if (this->total_sectors >= ATA_BIOS_LIMIT)
|
||||
if (this->total_sectors >= ATA_BIOS_LIMIT) {
|
||||
max_sectors = 255;
|
||||
else
|
||||
max_cylinders = 65535;
|
||||
} else {
|
||||
max_sectors = 63;
|
||||
max_cylinders = 16383;
|
||||
}
|
||||
|
||||
num_blocks = this->total_sectors;
|
||||
|
||||
for (heads = 16; heads > 0; heads--)
|
||||
if (!(num_blocks % heads))
|
||||
break;
|
||||
for (sectors = max_sectors; sectors > 0; sectors--)
|
||||
if (!(num_blocks % (heads * sectors)))
|
||||
if (heads * sectors * max_cylinders >= num_blocks) {
|
||||
cylinders = num_blocks / (heads * sectors);
|
||||
goto done;
|
||||
}
|
||||
|
||||
heads = 16;
|
||||
sectors = (num_blocks + heads * max_cylinders - 1) / (heads * max_cylinders);
|
||||
cylinders = (num_blocks + heads * sectors - 1) / (heads * sectors);
|
||||
|
||||
LOG_F(WARNING, "%s: could not find a suitable CHS translation; increased sectors to %d",
|
||||
this->name.c_str(), heads * sectors * cylinders);
|
||||
|
||||
done:
|
||||
this->heads = heads;
|
||||
|
||||
if (!heads) {
|
||||
LOG_F(WARNING, "%s: could not find a suitable number of heads",
|
||||
this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
num_blocks /= heads;
|
||||
|
||||
for (sectors = max_sectors; sectors > 0; sectors--) {
|
||||
if (!(num_blocks % sectors)) {
|
||||
if (num_blocks / sectors < 65536)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->sectors = sectors;
|
||||
|
||||
if (!sectors) {
|
||||
LOG_F(WARNING, "%s: could not find a suitable CHS translation",
|
||||
this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
this->cylinders = num_blocks / sectors;
|
||||
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), this->cylinders,
|
||||
this->heads, this->sectors);
|
||||
this->cylinders = cylinders;
|
||||
LOG_F(INFO, "%s: C=%d, H=%d, S=%d", this->name.c_str(), cylinders,
|
||||
heads, sectors);
|
||||
}
|
||||
|
||||
static const PropMap AtaHardDiskProperties = {
|
||||
static const PropMap AtaHardDisk_Properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtaHardDiskDescriptor =
|
||||
{AtaHardDisk::create, {}, AtaHardDiskProperties};
|
||||
static const DeviceDescription AtaHardDisk_Descriptor = {
|
||||
AtaHardDisk::create, {}, AtaHardDisk_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtaHardDisk, AtaHardDiskDescriptor);
|
||||
REGISTER_DEVICE(AtaHardDisk, AtaHardDisk_Descriptor);
|
||||
@@ -29,8 +29,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <string>
|
||||
|
||||
#define ATA_HD_SEC_SIZE 512
|
||||
#define ATA_BIOS_LIMIT 16514064
|
||||
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
|
||||
{
|
||||
@@ -63,9 +70,9 @@ private:
|
||||
uint8_t heads;
|
||||
uint8_t sectors;
|
||||
|
||||
char * buffer = new char[1 <<17];
|
||||
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
|
||||
|
||||
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
|
||||
char * buffer = new char[1 <<17];
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -87,7 +87,6 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
|
||||
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();
|
||||
@@ -149,6 +148,11 @@ int AtapiBaseDevice::perform_command() {
|
||||
this->r_status |= BSY;
|
||||
|
||||
switch (this->r_command) {
|
||||
case ATAPI_SOFT_RESET:
|
||||
this->device_reset(true);
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case ATAPI_PACKET:
|
||||
this->data_ptr = (uint16_t *)this->cmd_pkt;
|
||||
this->xfer_cnt = sizeof(this->cmd_pkt);
|
||||
|
||||
@@ -55,6 +55,7 @@ protected:
|
||||
uint16_t r_byte_count;
|
||||
bool status_expected = false;
|
||||
|
||||
alignas(uint16_t)
|
||||
uint8_t cmd_pkt[12] = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <string>
|
||||
#include <core/timermanager.h>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
@@ -132,8 +133,19 @@ void AtapiCdrom::perform_packet_command() {
|
||||
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(this->cmd_pkt, this->data_buf);
|
||||
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
|
||||
if (!this->xfer_cnt) {
|
||||
this->present_status();
|
||||
} else {
|
||||
@@ -146,6 +158,14 @@ void AtapiCdrom::perform_packet_command() {
|
||||
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 transfer length is zero then just complete command
|
||||
if (xfer_len == 0) {
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
@@ -157,8 +177,23 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
if (this->xfer_cnt > 0) {
|
||||
LOG_F(ERROR, "%s: READ(10) when transfer already in progress", name.c_str());
|
||||
|
||||
this->status_error(ScsiSense::NOT_READY, ScsiError::DEV_NOT_READY);
|
||||
this->present_status();
|
||||
break;
|
||||
}
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
|
||||
|
||||
// if transfer length is zero then just complete command
|
||||
if (xfer_len == 0) {
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
@@ -167,11 +202,24 @@ void AtapiCdrom::perform_packet_command() {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
#if 0
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(100), [this]() { this->data_out_phase(); });
|
||||
#else
|
||||
this->data_out_phase();
|
||||
#endif
|
||||
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 transfer length is zero then just complete command
|
||||
if (xfer_len == 0) {
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
@@ -192,6 +240,18 @@ void AtapiCdrom::perform_packet_command() {
|
||||
{
|
||||
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[9] == 0 && (this->cmd_pkt[10] & 7) == 0) {
|
||||
// Treat as a non-data command.
|
||||
xfer_len = 0;
|
||||
}
|
||||
|
||||
// if transfer length is zero then just complete command
|
||||
if (xfer_len == 0) {
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
}
|
||||
|
||||
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(),
|
||||
@@ -230,7 +290,8 @@ void AtapiCdrom::perform_packet_command() {
|
||||
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
|
||||
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
|
||||
}
|
||||
@@ -241,7 +302,8 @@ void AtapiCdrom::perform_packet_command() {
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
@@ -371,11 +433,12 @@ void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
|
||||
static const PropMap AtapiCdromProperties = {
|
||||
static const PropMap AtapiCdrom_Properties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtapiCdromDescriptor =
|
||||
{AtapiCdrom::create, {}, AtapiCdromProperties};
|
||||
static const DeviceDescription AtapiCdrom_Descriptor = {
|
||||
AtapiCdrom::create, {}, AtapiCdrom_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtapiCdrom, AtapiCdromDescriptor);
|
||||
REGISTER_DEVICE(AtapiCdrom, AtapiCdrom_Descriptor);
|
||||
@@ -29,7 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <string>
|
||||
|
||||
class AtapiCdrom : public AtapiBaseDevice, public CdromDrive {
|
||||
class AtapiCdrom : public CdromDrive, public AtapiBaseDevice {
|
||||
public:
|
||||
AtapiCdrom(std::string name);
|
||||
~AtapiCdrom() = default;
|
||||
|
||||
@@ -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
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** IDE Channel (aka IDE port) emulation.
|
||||
|
||||
One IDE channel is capable of controlling up to two IDE devices.
|
||||
This class handles device registration and passing of messages
|
||||
|
||||
IdeChannel class handles device registration and passing of messages
|
||||
from and to the host.
|
||||
|
||||
MacioIdeChannel class implements MacIO specific registers
|
||||
and interrupt handling.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
@@ -51,62 +55,73 @@ IdeChannel::IdeChannel(const std::string name)
|
||||
this->devices[1] = this->device_stub.get();
|
||||
}
|
||||
|
||||
int IdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IdeChannel::register_device(int id, AtaInterface* dev_obj) {
|
||||
if (id < 0 || id >= 2)
|
||||
ABORT_F("%s: invalid device ID", this->name.c_str());
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this);
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this, id);
|
||||
}
|
||||
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from the channel config", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size) {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
|
||||
void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to the channel config", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else {
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
}
|
||||
|
||||
int MacioIdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
this->irq_callback = [this](const uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t MacioIdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else
|
||||
return IdeChannel::read(reg_addr, size);
|
||||
}
|
||||
|
||||
void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else
|
||||
IdeChannel::write(reg_addr, val, size);
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
IdeChannel::create_first, {}, {}
|
||||
MacioIdeChannel::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
IdeChannel::create_second, {}, {}
|
||||
MacioIdeChannel::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -38,16 +39,6 @@ public:
|
||||
IdeChannel(const std::string name);
|
||||
~IdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
@@ -55,26 +46,56 @@ public:
|
||||
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
};
|
||||
}
|
||||
|
||||
bool is_device1_present() {
|
||||
return this->devices[1]->get_device_id() != ata_interface::DEVICE_ID_INVALID;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
void set_irq_callback(std::function<void(const uint8_t intrq_state)> cb) {
|
||||
this->irq_callback = cb;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->irq_callback(intrq_state);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
AtaInterface* devices[2];
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
};
|
||||
|
||||
/** This class models an IDE channel specific to MacIO ASICs. */
|
||||
class MacioIdeChannel : public IdeChannel
|
||||
{
|
||||
public:
|
||||
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
|
||||
~MacioIdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
private:
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
// interrupt stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
This is helpful especially for calculating video parameters.
|
||||
*/
|
||||
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <devices/common/clockgen/athens.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -40,14 +40,28 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr)
|
||||
{
|
||||
set_name("Athens");
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
|
||||
// set up power on values
|
||||
// This initialization is not prescribed
|
||||
// but let's set them to acceptable values anyway
|
||||
this->regs[AthensRegs::D2] = 2;
|
||||
this->regs[AthensRegs::N2] = 2;
|
||||
|
||||
// set P2_MUX2 on power up as follows:
|
||||
// - dot clock VCO is disabled
|
||||
// - dot clock = reference clock / 2
|
||||
this->regs[AthensRegs::P2_MUX2] = 0x62;
|
||||
}
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr, const float crystal_freq)
|
||||
: AthensClocks(dev_addr)
|
||||
{
|
||||
this->xtal_freq = crystal_freq;
|
||||
}
|
||||
|
||||
void AthensClocks::start_transaction()
|
||||
{
|
||||
this->pos = 0; // reset read/write position
|
||||
@@ -55,7 +69,7 @@ void AthensClocks::start_transaction()
|
||||
|
||||
bool AthensClocks::send_subaddress(uint8_t sub_addr)
|
||||
{
|
||||
LOG_F(INFO, "Athens: subaddress set to 0x%X", sub_addr);
|
||||
LOG_F(INFO, "%s: subaddress set to 0x%X", this->name.c_str(), sub_addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,16 +82,14 @@ bool AthensClocks::send_byte(uint8_t data)
|
||||
break;
|
||||
case 1:
|
||||
if (this->reg_num >= ATHENS_NUM_REGS) {
|
||||
LOG_F(WARNING, "Athens: invalid register number %d", this->reg_num);
|
||||
LOG_F(WARNING, "%s: invalid register number %d", this->name.c_str(),
|
||||
this->reg_num);
|
||||
return false; // return NACK
|
||||
}
|
||||
this->regs[this->reg_num] = data;
|
||||
if (reg_num == 3) {
|
||||
LOG_F(INFO, "Athens: dot clock frequency set to %d Hz", get_dot_freq());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Athens: too much data received!");
|
||||
LOG_F(WARNING, "%s: too much data received!", this->name.c_str());
|
||||
return false; // return NACK
|
||||
}
|
||||
return true;
|
||||
@@ -101,12 +113,12 @@ int AthensClocks::get_dot_freq()
|
||||
22, 27, 28, 31, 35, 37, 38, 42, 49, 55, 56, 78, 125
|
||||
};
|
||||
|
||||
if (this->regs[AthensRegs::P2_MUX2] & 0xC0) {
|
||||
LOG_F(INFO, "Athens: dot clock disabled");
|
||||
if (this->regs[AthensRegs::P2_MUX2] & 0x80) {
|
||||
LOG_F(INFO, "%s: dot clock disabled", this->name.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
float out_freq = 0.0f;
|
||||
float out_freq = 50000000.0; // for 800x600 72Hz
|
||||
|
||||
int d2 = this->regs[AthensRegs::D2];
|
||||
int n2 = this->regs[AthensRegs::N2];
|
||||
@@ -114,29 +126,31 @@ int AthensClocks::get_dot_freq()
|
||||
int post_div = 1 << (3 - (this->regs[AthensRegs::P2_MUX2] & 3));
|
||||
|
||||
if (std::find(D2_commons.begin(), D2_commons.end(), d2) == D2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested D2 value %d", d2);
|
||||
LOG_F(WARNING, "%s: untested D2 value %d", this->name.c_str(), d2);
|
||||
}
|
||||
|
||||
if (std::find(N2_commons.begin(), N2_commons.end(), n2) == N2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested N2 value %d", d2);
|
||||
LOG_F(WARNING, "%s: untested N2 value %d", this->name.c_str(), d2);
|
||||
}
|
||||
|
||||
int mux = (this->regs[AthensRegs::P2_MUX2] >> 4) & 3;
|
||||
|
||||
switch (mux) {
|
||||
case 0: // clock source -> dot cock VCO
|
||||
out_freq = ATHENS_XTAL * ((float)n2 / (float)(d2 * post_div));
|
||||
out_freq = this->xtal_freq * ((float)n2 / (float)(d2 * post_div));
|
||||
break;
|
||||
case 1: // clock source -> system clock VCO
|
||||
LOG_F(WARNING, "Athens: system clock VCO not supported yet!");
|
||||
LOG_F(WARNING, "%s: system clock VCO not supported yet!", this->name.c_str());
|
||||
break;
|
||||
case 2: // clock source -> crystal frequency
|
||||
out_freq = ATHENS_XTAL / post_div;
|
||||
out_freq = this->xtal_freq / post_div;
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(WARNING, "Athens: attempt to use reserved Mux value!");
|
||||
LOG_F(WARNING, "%s: attempt to use reserved Mux value!", this->name.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s: dot clock frequency set to %f MHz", this->name.c_str(), out_freq / 1000000.0);
|
||||
|
||||
return static_cast<int>(out_freq + 0.5f);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,9 +29,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define ATHENS_NUM_REGS 8
|
||||
constexpr auto ATHENS_NUM_REGS = 8;
|
||||
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f; // external crystal oscillator frequency
|
||||
/** Default external crystal oscillator frequency. */
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f;
|
||||
|
||||
namespace AthensRegs {
|
||||
|
||||
@@ -52,6 +53,7 @@ class AthensClocks : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
AthensClocks(uint8_t dev_addr);
|
||||
AthensClocks(uint8_t dev_addr, const float crystal_freq);
|
||||
~AthensClocks() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
@@ -68,8 +70,9 @@ private:
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t reg_num = 0;
|
||||
int pos = 0;
|
||||
float xtal_freq = ATHENS_XTAL;
|
||||
|
||||
uint8_t regs[ATHENS_NUM_REGS];
|
||||
uint8_t regs[ATHENS_NUM_REGS] = {};
|
||||
};
|
||||
|
||||
#endif // ATHENS_H
|
||||
+172
-32
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Descriptor-based direct memory access emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/dmacore.h>
|
||||
@@ -38,6 +39,12 @@ void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
|
||||
this->stop_cb = stop_cb;
|
||||
}
|
||||
|
||||
void DMAChannel::set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb) {
|
||||
this->in_cb = in_cb;
|
||||
this->out_cb = out_cb;
|
||||
this->flush_cb = flush_cb;
|
||||
}
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
DMACmd* DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd, bool *is_writable) {
|
||||
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
|
||||
@@ -81,11 +88,28 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
LOG_F(ERROR, "%s: Key > 0 not implemented", this->get_name().c_str());
|
||||
break;
|
||||
}
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->res_count = 0;
|
||||
this->cmd_in_progress = true;
|
||||
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)
|
||||
@@ -108,6 +132,7 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
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(),
|
||||
@@ -147,8 +172,7 @@ void DMAChannel::finish_cmd() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
this->ch_stat &= ~CH_STAT_BT;
|
||||
|
||||
// react to cmd.b (branch) bits
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
@@ -163,22 +187,29 @@ void DMAChannel::finish_cmd() {
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
branch_taken = true;
|
||||
this->ch_stat |= CH_STAT_BT;
|
||||
}
|
||||
}
|
||||
|
||||
this->update_irq();
|
||||
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->res_count);
|
||||
this->queue_len = 0;
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
|
||||
this->res_count = 0;
|
||||
}
|
||||
|
||||
if (!branch_taken)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -258,9 +289,11 @@ void DMAChannel::update_irq() {
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
if (int_ctrl)
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
else
|
||||
if (int_ctrl) {
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, 1);
|
||||
});
|
||||
} else
|
||||
LOG_F(ERROR, "%s Interrupt ignored", this->get_name().c_str());
|
||||
}
|
||||
}
|
||||
@@ -268,24 +301,27 @@ void DMAChannel::update_irq() {
|
||||
}
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
if (size != 4) {
|
||||
ABORT_F("%s: non-DWORD read from a DMA channel not supported",
|
||||
this->get_name().c_str());
|
||||
}
|
||||
uint32_t result = 0;
|
||||
|
||||
switch (offset) {
|
||||
switch (offset & ~3) {
|
||||
case DMAReg::CH_CTRL:
|
||||
return 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
|
||||
result = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
return BYTESWAP_32(this->ch_stat);
|
||||
result = this->ch_stat;
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
return BYTESWAP_32(this->cmd_ptr);
|
||||
result = this->cmd_ptr;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register read at 0x%X",
|
||||
this->get_name().c_str(), offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
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) {
|
||||
@@ -302,7 +338,7 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
mask = value >> 16;
|
||||
new_stat = (value & mask & 0xF0FFU) | (old_stat & ~mask);
|
||||
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)
|
||||
@@ -314,9 +350,15 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
// That means we need to update memory before channel operation
|
||||
// is aborted to prevent data loss.
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST &&
|
||||
this->flush_cb && (new_stat & CH_STAT_ACTIVE) &&
|
||||
!(this->ch_stat & CH_STAT_DEAD)) {
|
||||
this->flush_cb();
|
||||
} else {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
// partial memory updates no special action is taken here
|
||||
new_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
|
||||
@@ -334,9 +376,13 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->ch_stat = new_stat;
|
||||
}
|
||||
} else if ((new_stat & CH_STAT_WAKE) != (old_stat & CH_STAT_WAKE)) {
|
||||
new_stat |= CH_STAT_ACTIVE;
|
||||
this->ch_stat = new_stat;
|
||||
this->resume();
|
||||
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;
|
||||
@@ -349,7 +395,8 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_HI:
|
||||
if (value != 0) {
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x", this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
@@ -374,6 +421,54 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_from_device() {
|
||||
if (this->dev_obj == nullptr)
|
||||
return;
|
||||
|
||||
this->xfer_dir = DMA_DIR_FROM_DEV;
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_from(this->queue_data, this->queue_len);
|
||||
if (got_bytes == 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;
|
||||
|
||||
int got_bytes = this->dev_obj->xfer_to(this->queue_data, this->queue_len);
|
||||
if (got_bytes == this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_retry() {
|
||||
if (this->xfer_dir == DMA_DIR_UNDEF)
|
||||
return;
|
||||
|
||||
if (this->xfer_dir == DMA_DIR_FROM_DEV)
|
||||
this->xfer_from_device();
|
||||
else
|
||||
this->xfer_to_device();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_ready() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE) ||
|
||||
this->xfer_dir == DMA_DIR_UNDEF || this->cur_cmd >= DBDMA_Cmd::NOP)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
@@ -440,6 +535,41 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DMAChannel::end_pull_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::end_push_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
LOG_F(WARNING, "%s: Attempt to end push data to dead/idle channel",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->queue_len) {
|
||||
this->queue_len = 0;
|
||||
} else {
|
||||
this->ch_stat &= ~CH_STAT_FLUSH;
|
||||
}
|
||||
|
||||
// proceed with the DBDMA program
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
bool DMAChannel::is_out_active() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
return false;
|
||||
@@ -462,6 +592,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -490,6 +621,15 @@ void DMAChannel::resume() {
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
+22
-9
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -103,22 +103,30 @@ namespace DBDMA_Cmd {
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaBidirChannel {
|
||||
class DMAChannel : public DmaBidirChannel, public DmaChannel {
|
||||
public:
|
||||
DMAChannel(std::string name) : DmaBidirChannel(name) {}
|
||||
~DMAChannel() = default;
|
||||
|
||||
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
|
||||
void set_data_callbacks(DbdmaCallback in_cb, DbdmaCallback out_cb, DbdmaCallback flush_cb);
|
||||
uint32_t reg_read(uint32_t offset, int size);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
void set_stat(uint8_t new_stat) { this->ch_stat = (this->ch_stat & 0xff00) | new_stat; }
|
||||
|
||||
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);
|
||||
bool is_out_active() override;
|
||||
bool is_in_active() override;
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data) override;
|
||||
int push_data(const char* src_ptr, int len) override;
|
||||
int get_pull_data_remaining() override { return this->queue_len; }
|
||||
int get_push_data_remaining() override { return this->queue_len; }
|
||||
void end_pull_data() override;
|
||||
void end_push_data() override;
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint32_t irq_id) {
|
||||
bool is_ready() override;
|
||||
void xfer_retry() override;
|
||||
|
||||
void register_dma_int(InterruptCtrl* int_ctrl_obj, uint64_t irq_id) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
this->irq_id = irq_id;
|
||||
};
|
||||
@@ -129,6 +137,8 @@ protected:
|
||||
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);
|
||||
@@ -138,6 +148,9 @@ protected:
|
||||
private:
|
||||
std::function<void(void)> start_cb = nullptr; // DMA channel start callback
|
||||
std::function<void(void)> stop_cb = nullptr; // DMA channel stop callback
|
||||
std::function<void(void)> in_cb = nullptr; // DMA channel in callback
|
||||
std::function<void(void)> out_cb = nullptr; // DMA channel out callback
|
||||
std::function<void(void)> flush_cb = nullptr; // DMA channel flush callback
|
||||
|
||||
uint16_t ch_stat = 0;
|
||||
uint32_t cmd_ptr = 0;
|
||||
@@ -153,7 +166,7 @@ private:
|
||||
|
||||
// Interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint64_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif /* DB_DMA_H */
|
||||
#endif // DB_DMA_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum DmaPullResult : int {
|
||||
@@ -39,6 +40,8 @@ public:
|
||||
virtual bool is_out_active() { return true; };
|
||||
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data) = 0;
|
||||
virtual int get_pull_data_remaining() { return 1; };
|
||||
virtual void end_pull_data() { };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
@@ -52,6 +55,8 @@ public:
|
||||
|
||||
virtual bool is_in_active() { return true; };
|
||||
virtual int push_data(const char* src_ptr, int len) = 0;
|
||||
virtual int get_push_data_remaining() { return 1; };
|
||||
virtual void end_push_data() { };
|
||||
|
||||
std::string get_name(void) { return this->name; };
|
||||
|
||||
@@ -71,4 +76,56 @@ 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;
|
||||
|
||||
virtual void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
|
||||
virtual 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; };
|
||||
virtual int tell_xfer_size() { return 0; };
|
||||
|
||||
protected:
|
||||
DmaChannel* channel_obj = nullptr;
|
||||
};
|
||||
|
||||
class DmaChannel {
|
||||
public:
|
||||
DmaChannel() = default;
|
||||
~DmaChannel() = default;
|
||||
|
||||
virtual void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
|
||||
virtual void notify(DmaMsg msg) {};
|
||||
virtual bool is_ready() { return false; };
|
||||
virtual void xfer_retry() {};
|
||||
|
||||
protected:
|
||||
DmaDevice* dev_obj = nullptr;
|
||||
XferDir xfer_dir = DMA_DIR_UNDEF;
|
||||
};
|
||||
|
||||
/*
|
||||
TODO: write CONNECT macro that
|
||||
- constructs both DmaChannel and DmaDevice objects
|
||||
- calls connect() method on both objects
|
||||
- initializes DMA interrupts
|
||||
*/
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -46,6 +46,7 @@ enum HWCompType : uint64_t {
|
||||
SCSI_HOST = 1ULL << 21, // SCSI host adapter
|
||||
SCSI_DEV = 1ULL << 22, // SCSI device
|
||||
IDE_BUS = 1ULL << 23, // IDE bus
|
||||
IDE_HOST = 1ULL << 24, // IDE host controller
|
||||
IDE_DEV = 1ULL << 25, // IDE device
|
||||
SND_CODEC = 1ULL << 30, // sound codec
|
||||
SND_SERVER = 1ULL << 31, // host sound server
|
||||
|
||||
@@ -30,9 +30,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
enum IntSrc : uint32_t {
|
||||
INT_UNKNOWN = 0,
|
||||
VIA_CUDA,
|
||||
VIA2,
|
||||
SCSI_MESH,
|
||||
SCSI_CURIO,
|
||||
SWIM3,
|
||||
ESCC,
|
||||
SCCA,
|
||||
SCCB,
|
||||
ETHERNET,
|
||||
@@ -58,6 +60,7 @@ enum IntSrc : uint32_t {
|
||||
PLANB,
|
||||
VCI,
|
||||
PLATINUM,
|
||||
DMA_ALL,
|
||||
DMA_SCSI_MESH,
|
||||
DMA_SCSI_CURIO,
|
||||
DMA_SWIM3,
|
||||
@@ -71,6 +74,25 @@ enum IntSrc : uint32_t {
|
||||
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. */
|
||||
@@ -80,12 +102,17 @@ public:
|
||||
virtual ~InterruptCtrl() = default;
|
||||
|
||||
// register interrupt sources for a device
|
||||
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
|
||||
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
|
||||
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(uint32_t irq_id, uint8_t irq_line_state) = 0;
|
||||
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
|
||||
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-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,11 +27,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
public:
|
||||
|
||||
@@ -40,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
Machine ID register for Nubus Power Macs.
|
||||
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)
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
~BoardRegister() = default;
|
||||
|
||||
uint16_t iodev_read(uint32_t address) {
|
||||
return (!address) ? this->data : 0xFFFFU;
|
||||
return this->data;
|
||||
};
|
||||
|
||||
// appears read-only to guest
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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
|
||||
@@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -81,6 +82,10 @@ void NVram::init() {
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
+13
-14
@@ -41,7 +41,7 @@ using namespace std;
|
||||
static std::string hex2str(uint32_t n)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << setw(8) << setfill('0') << hex << n;
|
||||
ss << setw(8) << right << setfill('0') << hex << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ static uint32_t str2env(string& num_str) {
|
||||
|
||||
bool OfConfigAppl::validate() {
|
||||
int i;
|
||||
OfConfigHdrAppl hdr;
|
||||
OfConfigHdrAppl hdr{};
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
@@ -151,9 +151,9 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
|
||||
// populate the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
auto& name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
@@ -322,6 +322,9 @@ bool OfConfigChrp::validate()
|
||||
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.
|
||||
@@ -354,7 +357,7 @@ bool OfConfigChrp::validate()
|
||||
if (!of_part_found)
|
||||
return false;
|
||||
|
||||
OfConfigHdrChrp hdr;
|
||||
OfConfigHdrChrp hdr{};
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
|
||||
@@ -588,20 +591,16 @@ void OfConfigUtils::printenv() {
|
||||
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
|
||||
cout << setw(34) << left << var.first << val << right << endl; // name column has width 34
|
||||
}
|
||||
}
|
||||
|
||||
void OfConfigUtils::setenv(string var_name, string value)
|
||||
bool OfConfigUtils::setenv(string var_name, string value)
|
||||
{
|
||||
if (!this->open_container())
|
||||
return;
|
||||
return false;
|
||||
|
||||
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
if (!this->cfg_impl->set_var(var_name, value)) {
|
||||
cout << " Please try again" << endl;
|
||||
} else {
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
}
|
||||
return this->cfg_impl->set_var(var_name, value);
|
||||
}
|
||||
@@ -33,9 +33,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class NVram;
|
||||
|
||||
/** ========== Apple Open Firmware 1.x/2.x partition definitions. ========== */
|
||||
#define OF_NVRAM_OFFSET 0x1800
|
||||
#define OF_NVRAM_SIG 0x1275
|
||||
#define OF_CFG_SIZE 0x800
|
||||
constexpr auto OF_NVRAM_OFFSET = 0x1800;
|
||||
constexpr auto OF_NVRAM_SIG = 0x1275;
|
||||
constexpr auto OF_CFG_SIZE = 0x800;
|
||||
|
||||
// OF Variable types
|
||||
enum {
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
|
||||
int init();
|
||||
void printenv();
|
||||
void setenv(std::string var_name, std::string value);
|
||||
bool setenv(std::string var_name, std::string value);
|
||||
|
||||
protected:
|
||||
bool open_container();
|
||||
|
||||
+135
-62
@@ -79,6 +79,8 @@ uint32_t BanditPciDevice::pci_cfg_read(uint32_t reg_offs, AccessDetails &details
|
||||
return this->mode_ctrl;
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
return this->rd_hold_off_cnt;
|
||||
case BANDIT_DELAYED_AACK: // BANDIT_ONS
|
||||
return 0;
|
||||
default:
|
||||
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
@@ -103,6 +105,9 @@ void BanditPciDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDet
|
||||
case BANDIT_ARBUS_RD_HOLD_OFF:
|
||||
this->rd_hold_off_cnt = value & 0x1F;
|
||||
return;
|
||||
case BANDIT_DELAYED_AACK:
|
||||
// implement this for CATALYST and Platinum
|
||||
return;
|
||||
default:
|
||||
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
||||
}
|
||||
@@ -117,7 +122,7 @@ void BanditPciDevice::verbose_address_space()
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
|
||||
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++) {
|
||||
@@ -138,8 +143,21 @@ void BanditPciDevice::verbose_address_space()
|
||||
|
||||
uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
switch (offset >> 22) {
|
||||
case 3: // CONFIG_DATA
|
||||
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;
|
||||
@@ -155,18 +173,46 @@ uint32_t BanditHost::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
LOG_READ_NON_EXISTENT_PCI_DEVICE();
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
return BYTESWAP_32(this->config_addr);
|
||||
case 7:
|
||||
// Interrupt
|
||||
LOG_F(ERROR, "%s: Interrupt Acknowledge Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
|
||||
break;
|
||||
|
||||
default: // I/O space
|
||||
return pci_io_read_broadcast(offset, size);
|
||||
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 >> 22) {
|
||||
case 3: // CONFIG_DATA
|
||||
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;
|
||||
@@ -187,12 +233,23 @@ void BanditHost::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
LOG_WRITE_NON_EXISTENT_PCI_DEVICE();
|
||||
break;
|
||||
|
||||
case 2: // CONFIG_ADDR
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
case 7:
|
||||
// Special
|
||||
LOG_F(ERROR, "%s: Special Cycle 0x%08x unsupported", this->name.c_str(), offset & 0x001FFFFF);
|
||||
break;
|
||||
|
||||
default: // I/O space
|
||||
pci_io_write_broadcast(offset, size, value);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,46 +270,24 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num,
|
||||
}
|
||||
details.flags = PCI_CONFIG_TYPE_0;
|
||||
bus_num = 0; // use dummy value for bus number
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
device = NULL;
|
||||
return;
|
||||
if (is_aspen)
|
||||
dev_num = (this->config_addr >> 11) + 11; // IDSEL = 1 << (dev_num + 11)
|
||||
else {
|
||||
uint32_t idsel = this->config_addr & 0xFFFFF800U;
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {}
|
||||
LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL",
|
||||
this->name.c_str(), (uint32_t)this->config_addr);
|
||||
device = NULL;
|
||||
return;
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
}
|
||||
dev_num = WHAT_BIT_SET(idsel);
|
||||
device = pci_find_device(dev_num, fun_num);
|
||||
}
|
||||
|
||||
int BanditHost::device_postinit()
|
||||
{
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots1 = {
|
||||
{"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}
|
||||
};
|
||||
|
||||
static const std::map<std::string, int> pci_slots2 = {
|
||||
{"pci_D2", DEV_FUN(0xD,0)}, {"pci_E2", DEV_FUN(0xE,0)}, {"pci_F2", DEV_FUN(0xF,0)}
|
||||
};
|
||||
|
||||
static const std::map<std::string, int> vci_slots = {
|
||||
{"vci_D", DEV_FUN(0xD,0)}, {"vci_E", DEV_FUN(0xE,0)}, {"vci_F", DEV_FUN(0xF,0)}
|
||||
};
|
||||
|
||||
for (auto& slot :
|
||||
this->bridge_num == 0 ? vci_slots :
|
||||
this->bridge_num == 1 ? pci_slots1 :
|
||||
this->bridge_num == 2 ? pci_slots2 :
|
||||
pci_slots1
|
||||
) {
|
||||
pci_dev_name = GET_STR_PROP(slot.first);
|
||||
if (!pci_dev_name.empty()) {
|
||||
this->attach_pci_device(pci_dev_name, slot.second);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
int BanditHost::device_postinit() {
|
||||
return this->pcihost_device_postinit();
|
||||
}
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
@@ -269,14 +304,15 @@ Bandit::Bandit(int bridge_num, std::string name, int dev_id, int rev)
|
||||
|
||||
// add memory mapped I/O region for Bandit control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x000000 --> I/O space
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
// base_addr + 0x1000000 --> pass-through memory space (not included below)
|
||||
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
|
||||
// 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 = unique_ptr<BanditPciDevice>(
|
||||
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());
|
||||
@@ -298,6 +334,23 @@ Chaos::Chaos(std::string name) : BanditHost(0)
|
||||
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
AspenPci::AspenPci(std::string name) : BanditHost(1) {
|
||||
this->name = name;
|
||||
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
this->is_aspen = true;
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Aspen PCI control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
mem_ctrl->add_mmio_region(0xF2000000UL, 0x01000000, this);
|
||||
}
|
||||
|
||||
static const PropMap Bandit1_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
@@ -321,8 +374,23 @@ static const PropMap Chaos_Properties = {
|
||||
new StrProperty("")},
|
||||
{"vci_E",
|
||||
new StrProperty("")},
|
||||
{"vci_F",
|
||||
};
|
||||
|
||||
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 std::vector<std::string> Chaos_Subdevices = {
|
||||
"ControlVideo"
|
||||
};
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
@@ -334,14 +402,19 @@ static const DeviceDescription Bandit2_Descriptor = {
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, Bandit1_Properties
|
||||
Bandit::create_psx_first, {}, PsxPci1_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, {}, Chaos_Properties
|
||||
Chaos::create, Chaos_Subdevices, Chaos_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
static const DeviceDescription AspenPci1_Descriptor = {
|
||||
AspenPci::create, {}, Bandit1_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Bandit2, Bandit2_Descriptor);
|
||||
REGISTER_DEVICE(PsxPci1, PsxPci1_Descriptor);
|
||||
REGISTER_DEVICE(AspenPci1, AspenPci1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
@@ -46,8 +46,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#define BANDIT_DEV (11) // Bandit's own device number
|
||||
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
|
||||
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)
|
||||
@@ -60,6 +60,7 @@ enum {
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
BANDIT_MODE_SELECT = 0x50,
|
||||
BANDIT_ARBUS_RD_HOLD_OFF = 0x58,
|
||||
BANDIT_DELAYED_AACK = 0x60,
|
||||
};
|
||||
|
||||
/** checks if one bit is set at time, return 0 if not */
|
||||
@@ -72,18 +73,16 @@ class BanditHost : public PCIHost, public MMIODevice {
|
||||
public:
|
||||
BanditHost(int bridge_num) { this->bridge_num = bridge_num; };
|
||||
|
||||
// PCIHost methods
|
||||
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
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();
|
||||
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,
|
||||
@@ -133,8 +132,8 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
std::unique_ptr<BanditPciDevice> my_pci_device;
|
||||
uint32_t base_addr;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -150,4 +149,17 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
Aspen PCI Bridge HLE emulation class.
|
||||
*/
|
||||
class AspenPci : public BanditHost {
|
||||
public:
|
||||
AspenPci(std::string name);
|
||||
~AspenPci() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AspenPci>(new AspenPci("Aspen-PCI1"));
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -86,8 +86,28 @@ void DecPciBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetail
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -44,6 +44,10 @@ public:
|
||||
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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,7 +32,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
PCIBase::PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars)
|
||||
{
|
||||
this->name = name;
|
||||
this->pci_name = name;
|
||||
this->hdr_type = hdr_type;
|
||||
this->num_bars = num_bars;
|
||||
|
||||
@@ -162,17 +161,17 @@ int PCIBase::attach_exp_rom_image(const std::string img_path)
|
||||
|
||||
if (exp_rom_image_size == this->exp_rom_size) {
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).",
|
||||
this->pci_name.c_str(), this->exp_rom_size);
|
||||
this->get_name().c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).",
|
||||
this->pci_name.c_str(), (int)exp_rom_image_size, this->exp_rom_size);
|
||||
this->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->pci_name.c_str(), exc.what());
|
||||
LOG_F(ERROR, "%s: %s", this->get_name().c_str(), exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
@@ -192,7 +191,8 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
|
||||
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->pci_name.c_str(), bar_num, (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;
|
||||
|
||||
@@ -201,7 +201,8 @@ void PCIBase::set_bar_value(int bar_num, uint32_t value)
|
||||
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->pci_name.c_str(), bar_num, (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;
|
||||
|
||||
@@ -239,11 +240,11 @@ void PCIBase::finish_config_bars()
|
||||
case 2:
|
||||
if (bar_num >= num_bars - 1) {
|
||||
ABORT_F("%s: BAR %d cannot be 64-bit",
|
||||
this->pci_name.c_str(), bar_num);
|
||||
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->pci_name.c_str(), bar_num);
|
||||
this->get_name().c_str(), bar_num);
|
||||
}
|
||||
else {
|
||||
bars_typ[bar_num++] = PCIBarType::Mem_64_Bit_Lo;
|
||||
@@ -252,7 +253,7 @@ void PCIBase::finish_config_bars()
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: invalid or unsupported PCI space type %d for BAR %d",
|
||||
this->pci_name.c_str(), pci_space_type, bar_num);
|
||||
this->get_name().c_str(), pci_space_type, bar_num);
|
||||
} // switch pci_space_type
|
||||
}
|
||||
} // for bar_num
|
||||
@@ -302,3 +303,21 @@ void PCIBase::pci_wr_exp_rom_bar(uint32_t data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,16 +47,19 @@ enum {
|
||||
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_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_NVIDIA = 0x10DE,
|
||||
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 */
|
||||
@@ -76,6 +79,7 @@ typedef struct {
|
||||
} BarConfig;
|
||||
|
||||
class PCIBase : public MMIODevice {
|
||||
friend class PCIHost;
|
||||
public:
|
||||
PCIBase(std::string name, PCIHeaderType hdr_type, int num_bars);
|
||||
virtual ~PCIBase() = default;
|
||||
@@ -125,10 +129,12 @@ public:
|
||||
this->irq_pin = irq_pin;
|
||||
}
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state) {
|
||||
this->host_instance->pci_interrupt(irq_line_state, this);
|
||||
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) { }
|
||||
@@ -141,8 +147,7 @@ protected:
|
||||
void map_exp_rom_mem();
|
||||
void unmap_exp_rom_mem();
|
||||
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
|
||||
// PCI configuration space state (type 0, 1, and 2)
|
||||
uint16_t vendor_id;
|
||||
@@ -174,6 +179,8 @@ protected:
|
||||
|
||||
// 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) {
|
||||
@@ -233,7 +240,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
#define LOG_READ_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
"%s err: read attempt from non-existent PCI device %02x:%02x.%x @%02x.%c", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size) \
|
||||
)
|
||||
@@ -241,7 +248,7 @@ inline uint32_t pci_cfg_log(uint32_t value, AccessDetails &details) {
|
||||
#define LOG_WRITE_NON_EXISTENT_PCI_DEVICE() \
|
||||
LOG_F( \
|
||||
ERROR, \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
"%s err: write attempt to non-existent PCI device %02x:%02x.%x @%02x.%c = %0*x", \
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + details.offset, \
|
||||
SIZE_ARG(details.size), \
|
||||
details.size * 2, BYTESWAP_SIZED(value, details.size) \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -165,14 +165,22 @@ void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &
|
||||
|
||||
bool PCIBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
if (!(this->command & 1))
|
||||
return false;
|
||||
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
|
||||
return false;
|
||||
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
if (!(this->command & 1))
|
||||
return false;
|
||||
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
|
||||
return false;
|
||||
|
||||
return this->pci_io_write_loop(offset, size, value);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -42,7 +42,7 @@ PCIBridgeBase::PCIBridgeBase(std::string name, PCIHeaderType hdr_type, int num_b
|
||||
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)
|
||||
AddressMapEntry* 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);
|
||||
@@ -85,3 +85,7 @@ void PCIBridgeBase::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetai
|
||||
return PCIBase::pci_cfg_write(reg_offs, value, details);
|
||||
}
|
||||
}
|
||||
|
||||
int PCIBridgeBase::device_postinit() {
|
||||
return this->pcihost_device_postinit();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -43,12 +43,16 @@ public:
|
||||
~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);
|
||||
virtual AddressMapEntry* pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj) override;
|
||||
|
||||
// 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 uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details) override;
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details) override;
|
||||
|
||||
bool supports_io_space() override {
|
||||
return true;
|
||||
};
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
@@ -64,6 +68,9 @@ public:
|
||||
std::function<uint16_t()> pci_rd_bridge_control;
|
||||
std::function<void(uint16_t)> pci_wr_bridge_control;
|
||||
|
||||
// HWComponent methods
|
||||
virtual int device_postinit() override;
|
||||
|
||||
protected:
|
||||
// PCI configuration space state
|
||||
uint8_t primary_bus = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,19 +23,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/pci/pcibridge.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
|
||||
bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
{
|
||||
// return false if dev_fun_num already registered
|
||||
if (this->dev_map.count(dev_fun_num))
|
||||
return false;
|
||||
if (this->dev_map.count(dev_fun_num)) {
|
||||
pci_unregister_device(dev_fun_num);
|
||||
}
|
||||
|
||||
int fun_num = dev_fun_num & 7;
|
||||
int dev_num = (dev_fun_num >> 3) & 0x1f;
|
||||
@@ -69,7 +70,26 @@ bool PCIHost::pci_register_device(int dev_fun_num, PCIBase* dev_instance)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
void PCIHost::pci_unregister_device(int dev_fun_num)
|
||||
{
|
||||
if (!this->dev_map.count(dev_fun_num)) {
|
||||
return;
|
||||
}
|
||||
auto dev_instance = this->dev_map[dev_fun_num];
|
||||
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
// FIXME: need destructors to remove memory regions and downstream devices.
|
||||
ERROR, "%s: pci_unregister_device(%s) not supported yet (every PCI device needs "
|
||||
"a working destructor to unregister memory and downstream devices etc.)",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", dev_instance->get_name().c_str()
|
||||
);
|
||||
|
||||
this->dev_map.erase(dev_fun_num);
|
||||
gMachineObj->remove_device(dev_instance); // calls destructor of dev_instance since it is a unique_ptr in the device_map.
|
||||
}
|
||||
|
||||
AddressMapEntry* PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
@@ -102,9 +122,8 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
}
|
||||
|
||||
// attempt to create device object
|
||||
MachineFactory::register_device_settings(dev_name);
|
||||
auto desc = DeviceRegistry::get_descriptor(dev_name);
|
||||
map<string, string> settings;
|
||||
MachineFactory::get_device_settings(desc, settings);
|
||||
auto dev_obj = desc.m_create_func();
|
||||
|
||||
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
|
||||
@@ -121,6 +140,7 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
gMachineObj->add_device(dev_name + dev_suffix, std::move(dev_obj));
|
||||
|
||||
PCIBase *dev = dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name(dev_name + dev_suffix));
|
||||
dev->set_name(dev->get_name() + dev_suffix);
|
||||
|
||||
// register device with the PCI host
|
||||
this->pci_register_device(slot_id, dev);
|
||||
@@ -128,6 +148,50 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
return dev;
|
||||
}
|
||||
|
||||
InterruptCtrl *PCIHost::get_interrupt_controller() {
|
||||
if (!this->int_ctrl) {
|
||||
InterruptCtrl *int_ctrl_obj =
|
||||
dynamic_cast<InterruptCtrl*>(gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
}
|
||||
return this->int_ctrl;
|
||||
}
|
||||
|
||||
bool PCIHost::register_pci_int(PCIBase* dev_instance) {
|
||||
bool dev_found = false;
|
||||
int dev_fun_num = 0;
|
||||
|
||||
for (auto& dev : this->dev_map) {
|
||||
if (dev.second == dev_instance) {
|
||||
dev_fun_num = dev.first;
|
||||
dev_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev_found)
|
||||
ABORT_F("register_pci_int: requested device not found");
|
||||
|
||||
for (auto& irq : this->my_irq_map) {
|
||||
if (irq.dev_fun_num == dev_fun_num) {
|
||||
IntDetails new_int_detail;
|
||||
new_int_detail.int_ctrl_obj = this->get_interrupt_controller();
|
||||
if (new_int_detail.int_ctrl_obj && irq.int_src)
|
||||
new_int_detail.irq_id = new_int_detail.int_ctrl_obj->register_dev_int(irq.int_src);
|
||||
dev_instance->set_int_details(new_int_detail);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PCIBridgeBase *self = dynamic_cast<PCIBridgeBase*>(this);
|
||||
if (self) {
|
||||
if (!self->int_details.int_ctrl_obj)
|
||||
self->host_instance->register_pci_int(self);
|
||||
dev_instance->set_int_details(self->int_details);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
@@ -151,18 +215,21 @@ bool PCIHost::pci_io_write_loop(uint32_t offset, int size, uint32_t value)
|
||||
uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res;
|
||||
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_read_loop (offset, size, res)) {
|
||||
if (pci_io_read_loop(offset, size, res))
|
||||
return res;
|
||||
}
|
||||
|
||||
// no device has accepted the request -> report error
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
|
||||
hwc ? hwc->get_name().c_str() : "PCIHost", offset,
|
||||
SIZE_ARG(size)
|
||||
);
|
||||
// FIXME: add machine check exception (DEFAULT CATCH!, code=FFF00200)
|
||||
// machine check exception (DEFAULT CATCH!, code=FFF00200)
|
||||
ppc_exception_handler(Except_Type::EXC_MACHINE_CHECK, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -170,9 +237,10 @@ void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_write_loop(offset, size, value)) {
|
||||
if (pci_io_write_loop(offset, size, value))
|
||||
return;
|
||||
}
|
||||
|
||||
// no device has accepted the request -> report error
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
|
||||
@@ -204,3 +272,19 @@ PCIBase *PCIHost::pci_find_device(uint8_t dev_num, uint8_t fun_num)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int PCIHost::pcihost_device_postinit()
|
||||
{
|
||||
std::string pci_dev_name;
|
||||
|
||||
for (auto& slot : this->my_irq_map) {
|
||||
if (slot.slot_name) {
|
||||
pci_dev_name = GET_STR_PROP(slot.slot_name);
|
||||
if (!pci_dev_name.empty()) {
|
||||
this->attach_pci_device(pci_dev_name, slot.dev_fun_num, std::string("@") + slot.slot_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,6 +23,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -49,6 +51,12 @@ typedef struct AccessDetails {
|
||||
|
||||
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
|
||||
|
||||
typedef struct {
|
||||
const char * slot_name;
|
||||
int dev_fun_num;
|
||||
IntSrc int_src;
|
||||
} PciIrqMap;
|
||||
|
||||
class PCIBase;
|
||||
class PCIBridgeBase;
|
||||
|
||||
@@ -61,9 +69,10 @@ public:
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_fun_num, PCIBase* dev_instance);
|
||||
virtual void pci_unregister_device(int dev_fun_num);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual bool pci_unregister_mmio_region(uint32_t start_addr, uint32_t size, PCIBase* obj);
|
||||
virtual AddressMapEntry* 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);
|
||||
|
||||
virtual void attach_pci_device(const std::string& dev_name, int slot_id);
|
||||
PCIBase *attach_pci_device(const std::string& dev_name, int slot_id,
|
||||
@@ -78,12 +87,24 @@ public:
|
||||
virtual PCIBase *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num);
|
||||
virtual PCIBase *pci_find_device(uint8_t dev_num, uint8_t fun_num);
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
|
||||
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
|
||||
this->my_irq_map = irq_map;
|
||||
};
|
||||
virtual int pcihost_device_postinit();
|
||||
|
||||
virtual bool register_pci_int(PCIBase* dev_instance);
|
||||
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
};
|
||||
virtual InterruptCtrl *get_interrupt_controller();
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIBase*> dev_map;
|
||||
std::vector<PCIBase*> io_space_devs;
|
||||
std::vector<PCIBridgeBase*> bridge_devs;
|
||||
std::vector<PciIrqMap> my_irq_map;
|
||||
|
||||
InterruptCtrl *int_ctrl = nullptr;
|
||||
};
|
||||
|
||||
// Helpers for data conversion in the PCI Configuration space.
|
||||
|
||||
+140
-109
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
@@ -33,9 +34,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit()
|
||||
{
|
||||
int MeshController::device_postinit() {
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiMesh"));
|
||||
if (bus_obj) {
|
||||
bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
bus_obj->attach_scsi_devices("2");
|
||||
}
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
@@ -44,27 +48,28 @@ int MeshController::device_postinit()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshController::reset(bool is_hard_reset)
|
||||
{
|
||||
void MeshController::reset(bool is_hard_reset) {
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->fifo_cnt = 0;
|
||||
this->fifo_pos = 0;
|
||||
this->int_mask = 0;
|
||||
this->exception = 0;
|
||||
this->xfer_count = 0;
|
||||
this->src_id = 7;
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MeshController::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t MeshController::read(uint8_t reg_offset) {
|
||||
switch(reg_offset) {
|
||||
case MeshReg::XferCount0:
|
||||
return this->xfer_count & 0xFFU;
|
||||
case MeshReg::XferCount1:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
case MeshReg::FIFO:
|
||||
return this->fifo_pop();
|
||||
case MeshReg::Sequence:
|
||||
return this->cur_cmd;
|
||||
case MeshReg::BusStatus0:
|
||||
@@ -72,9 +77,9 @@ uint8_t MeshController::read(uint8_t reg_offset)
|
||||
case MeshReg::BusStatus1:
|
||||
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
|
||||
case MeshReg::FIFOCount:
|
||||
return this->fifo_cnt;
|
||||
return this->fifo_pos;
|
||||
case MeshReg::Exception:
|
||||
return 0;
|
||||
return this->exception;
|
||||
case MeshReg::Error:
|
||||
return 0;
|
||||
case MeshReg::IntMask:
|
||||
@@ -94,27 +99,27 @@ uint8_t MeshController::read(uint8_t reg_offset)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint16_t new_stat;
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value) {
|
||||
//uint16_t new_stat;
|
||||
|
||||
switch(reg_offset) {
|
||||
case MeshReg::XferCount0:
|
||||
this->xfer_count = (this->xfer_count & ~0xFFU) | value;
|
||||
break;
|
||||
case MeshReg::XferCount1:
|
||||
this->xfer_count = (this->xfer_count & ~0xFF00U) | (value << 8);
|
||||
break;
|
||||
case MeshReg::FIFO:
|
||||
this->fifo_push(value);
|
||||
break;
|
||||
case MeshReg::Sequence:
|
||||
perform_command(value);
|
||||
break;
|
||||
case MeshReg::BusStatus0:
|
||||
this->update_bus_status((this->bus_stat & 0xFF00U) | value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
new_stat = value << 8;
|
||||
if (new_stat != this->bus_stat) {
|
||||
for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
this->update_bus_status((this->bus_stat & 0xFFU) | (value << 8));
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
this->int_mask = value;
|
||||
@@ -141,28 +146,87 @@ void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::perform_command(const uint8_t cmd)
|
||||
{
|
||||
void MeshController::perform_command(const uint8_t cmd) {
|
||||
this->cur_cmd = cmd;
|
||||
|
||||
this->int_stat &= ~INT_CMD_DONE;
|
||||
|
||||
this->is_dma_cmd = !!(this->cur_cmd & 0x80);
|
||||
|
||||
switch (this->cur_cmd & 0xF) {
|
||||
case SeqCmd::Arbitrate:
|
||||
this->exception &= EXC_ARB_LOST;
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Select:
|
||||
this->cur_state = SeqState::SEL_BEGIN;
|
||||
this->assert_atn = !!(this->cur_cmd & 0x20);
|
||||
this->exception &= EXC_SEL_TIMEOUT;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEL_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Command:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
|
||||
LOG_F(WARNING, "%s: not in COMMAND phase", this->name.c_str());
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_CMD;
|
||||
if (this->fifo_pos)
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Status:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS)
|
||||
LOG_F(WARNING, "%s: not in STATUS phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_STATUS;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DataOut:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::DATA_OUT)
|
||||
LOG_F(WARNING, "%s: not in DATA OUT phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DataIn:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::DATA_IN)
|
||||
LOG_F(WARNING, "%s: not in DATA IN phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::MessageOut:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_OUT)
|
||||
LOG_F(WARNING, "%s: not in MESSAGE OUT phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_MSG;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::MessageIn:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_IN)
|
||||
LOG_F(WARNING, "%s: not in MESSAGE IN phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_MESSAGE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::BusFree:
|
||||
LOG_F(INFO, "MESH: BusFree stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
// generate phase mismatch exception
|
||||
// if the target is still connected
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
|
||||
this->exception |= EXC_PHASE_MM;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
} else // say ok because we got the expected bus free phase
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->update_irq();
|
||||
break;
|
||||
case SeqCmd::EnaParityCheck:
|
||||
this->check_parity = true;
|
||||
break;
|
||||
case SeqCmd::DisParityCheck:
|
||||
this->check_parity = false;
|
||||
break;
|
||||
case SeqCmd::EnaReselect:
|
||||
LOG_F(INFO, "MESH: EnaReselect stub invoked");
|
||||
LOG_F(9, "MESH: EnaReselect stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::DisReselect:
|
||||
@@ -172,95 +236,62 @@ void MeshController::perform_command(const uint8_t cmd)
|
||||
case SeqCmd::ResetMesh:
|
||||
this->reset(false);
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->fifo_pos = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
void MeshController::update_bus_status(const uint16_t new_stat) {
|
||||
uint16_t mask;
|
||||
|
||||
// update the lower part (BusStatus0)
|
||||
if ((new_stat ^ this->bus_stat) & 0xFF) {
|
||||
for (mask = SCSI_CTRL_REQ; mask >= SCSI_CTRL_IO; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the upper part (BusStatus1)
|
||||
if ((new_stat ^ this->bus_stat) & 0xFF00U) {
|
||||
for (mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
|
||||
void MeshController::sequencer()
|
||||
{
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "MESH: arbitration error, bus not free!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "MESH: arbitration lost!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->exception |= EXC_ARB_LOST;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->cur_cmd & 0x20);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "MESH: selection completed");
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
void MeshController::step_completed() {
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void MeshController::report_error(const int error) {
|
||||
switch(error) {
|
||||
case SEL_TIMEOUT:
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("MESH: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::update_irq()
|
||||
{
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
ABORT_F("%s: unhandled error %d", this->name.c_str(), error);
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
static const PropMap Mesh_properties = {
|
||||
|
||||
+78
-110
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,106 +25,96 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define MESH_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsibusctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class InterruptCtrl;
|
||||
class ScsiBus;
|
||||
|
||||
// Chip ID returned by the MESH ASIC on TNT machines (Apple part 343S1146-a)
|
||||
#define TntMeshID 0xE2
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
#define HeathrowMeshID 4
|
||||
|
||||
namespace MeshScsi {
|
||||
/** MESH registers offsets. */
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
|
||||
// MESH registers offsets.
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
/** MESH Sequencer commands. */
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0x0,
|
||||
Arbitrate = 0x1,
|
||||
Select = 0x2,
|
||||
Command = 0x3,
|
||||
Status = 0x4,
|
||||
DataOut = 0x5,
|
||||
DataIn = 0x6,
|
||||
MessageOut = 0x7,
|
||||
MessageIn = 0x8,
|
||||
BusFree = 0x9,
|
||||
EnaParityCheck = 0xA,
|
||||
DisParityCheck = 0xB,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF
|
||||
};
|
||||
|
||||
// MESH Sequencer commands.
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0,
|
||||
Arbitrate = 1,
|
||||
Select = 2,
|
||||
BusFree = 9,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF,
|
||||
};
|
||||
|
||||
// Exception register bits.
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
// Interrupt register bits.
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
|
||||
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
/** Exception register bits. */
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
/** Interrupt register bits. */
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
}; // namespace MeshScsi
|
||||
|
||||
class MeshStub : public HWComponent {
|
||||
class MeshBase {
|
||||
public:
|
||||
MeshBase() = default;
|
||||
~MeshBase() = default;
|
||||
virtual uint8_t read(uint8_t reg_offset) = 0;
|
||||
virtual void write(uint8_t reg_offset, uint8_t value) = 0;
|
||||
};
|
||||
|
||||
class MeshStub : public MeshBase {
|
||||
public:
|
||||
MeshStub() = default;
|
||||
~MeshStub() = default;
|
||||
|
||||
// registers access
|
||||
uint8_t read(uint8_t reg_offset) { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) {};
|
||||
uint8_t read(uint8_t reg_offset) override { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) override {};
|
||||
};
|
||||
|
||||
class MeshController : public HWComponent {
|
||||
class MeshController : public ScsiBusController, public MeshBase {
|
||||
public:
|
||||
MeshController(uint8_t mesh_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
|
||||
this->chip_id = mesh_id;
|
||||
this->set_name("MESH");
|
||||
this->reset(true);
|
||||
};
|
||||
~MeshController() = default;
|
||||
@@ -134,55 +124,33 @@ public:
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_heathrow() {
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMESHID));
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMeshID));
|
||||
}
|
||||
|
||||
// MESH registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
// MeshBase methods
|
||||
uint8_t read(uint8_t reg_offset) override;
|
||||
void write(uint8_t reg_offset, uint8_t value) override;
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
int device_postinit() override;
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
// ScsiBusController methods
|
||||
void step_completed() override;
|
||||
void report_error(const int error) override;
|
||||
|
||||
protected:
|
||||
void reset(bool is_hard_reset);
|
||||
void perform_command(const uint8_t cmd);
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void sequencer();
|
||||
void update_irq();
|
||||
void update_bus_status(const uint16_t new_stat);
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
uint8_t int_mask;
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t sync_params;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
uint8_t cur_cmd;
|
||||
uint8_t error;
|
||||
uint8_t fifo_cnt;
|
||||
uint8_t exception;
|
||||
uint32_t xfer_count;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
uint8_t exception = 0;
|
||||
uint16_t bus_stat;
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id;
|
||||
uint32_t cur_state;
|
||||
uint32_t next_state;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
bool check_parity = true;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
+329
-99
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -33,7 +33,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id)
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id), DmaDevice()
|
||||
{
|
||||
this->chip_id = chip_id;
|
||||
this->my_bus_id = my_id;
|
||||
@@ -43,10 +43,10 @@ Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id)
|
||||
|
||||
int Sc53C94::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
|
||||
if (this->bus_obj) {
|
||||
this->bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
this->bus_obj->attach_scsi_devices("");
|
||||
ScsiBus* bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiCurio"));
|
||||
if (bus) {
|
||||
bus->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
bus->attach_scsi_devices("");
|
||||
}
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
@@ -59,7 +59,7 @@ int Sc53C94::device_postinit()
|
||||
void Sc53C94::reset_device()
|
||||
{
|
||||
// part-unique ID to be read using a magic sequence
|
||||
this->set_xfer_count = this->chip_id << 16;
|
||||
this->xfer_count = this->chip_id << 16;
|
||||
|
||||
this->clk_factor = 2;
|
||||
this->sel_timeout = 0;
|
||||
@@ -72,14 +72,19 @@ void Sc53C94::reset_device()
|
||||
this->data_fifo_pos = 0;
|
||||
this->data_fifo[0] = 0;
|
||||
|
||||
this->sync_period = 5;
|
||||
this->sync_offset = 0;
|
||||
|
||||
this->cur_step = 0;
|
||||
this->seq_step = 0;
|
||||
|
||||
this->status = 0;
|
||||
this->status &= STAT_PHASE_MASK; // reset doesn't affect bus phase bits
|
||||
this->int_status = 0;
|
||||
}
|
||||
|
||||
uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t status, int_status;
|
||||
uint8_t bus_phase, int_flags;
|
||||
|
||||
switch (reg_offset) {
|
||||
case Read::Reg53C94::Xfer_Cnt_LSB:
|
||||
@@ -91,18 +96,25 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
case Read::Reg53C94::Command:
|
||||
return this->cmd_fifo[0];
|
||||
case Read::Reg53C94::Status:
|
||||
status = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
return (this->status & 0xF8) | status;
|
||||
if (this->config2 & CFG2_ENF) {
|
||||
LOG_F(WARNING, "%s: phase latch not implemented", this->name.c_str());
|
||||
bus_phase = SCSI_CTRL_MSG; // use reserved bus phase
|
||||
} else
|
||||
bus_phase = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
return (this->status & 0xF8) | bus_phase;
|
||||
case Read::Reg53C94::Int_Status:
|
||||
int_status = this->int_status;
|
||||
this->seq_step = 0;
|
||||
this->int_status = 0;
|
||||
int_flags = this->int_status;
|
||||
if (this->irq) {
|
||||
this->status &= ~(STAT_GE | STAT_PE | STAT_GCV);
|
||||
this->int_status = 0;
|
||||
this->seq_step = 0;
|
||||
}
|
||||
this->update_irq();
|
||||
return int_status;
|
||||
return int_flags;
|
||||
case Read::Reg53C94::Seq_Step:
|
||||
return this->seq_step;
|
||||
case Read::Reg53C94::FIFO_Flags:
|
||||
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
|
||||
return (this->cur_step << 5) | (this->data_fifo_pos & 0x1F);
|
||||
case Read::Reg53C94::Config_1:
|
||||
return this->config1;
|
||||
case Read::Reg53C94::Config_3:
|
||||
@@ -139,6 +151,9 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
case Write::Reg53C94::Sel_Timeout:
|
||||
this->sel_timeout = value;
|
||||
break;
|
||||
case Write::Reg53C94::Sync_Period:
|
||||
this->sync_period = value;
|
||||
break;
|
||||
case Write::Reg53C94::Sync_Offset:
|
||||
this->sync_offset = value;
|
||||
break;
|
||||
@@ -172,7 +187,7 @@ uint16_t Sc53C94::pseudo_dma_read()
|
||||
// remove one word from FIFO
|
||||
data_word = (this->data_fifo[0] << 8) | this->data_fifo[1];
|
||||
this->data_fifo_pos -= 2;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
std::memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
|
||||
// update DMA status
|
||||
if (this->is_dma_cmd) {
|
||||
@@ -215,14 +230,14 @@ void Sc53C94::pseudo_dma_write(uint16_t data) {
|
||||
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
|
||||
if (this->on_reset && (cmd & CMD_OPCODE) != CMD_NOP) {
|
||||
LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Reset Device (chip), Reset Bus and DMA Stop commands execute
|
||||
// immediately while all others are placed into the command FIFO
|
||||
switch (cmd & 0x7F) {
|
||||
switch (cmd & CMD_OPCODE) {
|
||||
case CMD_RESET_DEVICE:
|
||||
case CMD_RESET_BUS:
|
||||
case CMD_DMA_STOP:
|
||||
@@ -243,9 +258,9 @@ void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
|
||||
void Sc53C94::exec_command()
|
||||
{
|
||||
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
|
||||
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & CMD_OPCODE;
|
||||
|
||||
this->is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
|
||||
this->is_dma_cmd = !!(this->cmd_fifo[0] & CMD_ISDMA);
|
||||
|
||||
if (this->is_dma_cmd) {
|
||||
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
|
||||
@@ -258,6 +273,8 @@ void Sc53C94::exec_command()
|
||||
}
|
||||
}
|
||||
|
||||
this->cmd_steps = nullptr; // assume a single-step command for now
|
||||
|
||||
// simple commands will be executed immediately
|
||||
// complex commands will be broken into multiple steps
|
||||
// and handled by the sequencer
|
||||
@@ -280,14 +297,20 @@ void Sc53C94::exec_command()
|
||||
// assert RST line
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
// release RST line after 25 us
|
||||
if (my_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->my_timer_id);
|
||||
my_timer_id = 0;
|
||||
}
|
||||
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(25),
|
||||
[this]() {
|
||||
my_timer_id = 0;
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
|
||||
});
|
||||
if (!(config1 & 0x40)) {
|
||||
if (!(config1 & CFG1_DISR)) {
|
||||
LOG_F(INFO, "%s: reset interrupt issued", this->name.c_str());
|
||||
this->int_status = INTSTAT_SRST;
|
||||
this->update_irq();
|
||||
}
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -298,62 +321,86 @@ void Sc53C94::exec_command()
|
||||
this->int_status = INTSTAT_ICMD;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = nullptr;
|
||||
this->cur_state = SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
}
|
||||
break;
|
||||
case CMD_COMPLETE_STEPS:
|
||||
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
|
||||
{SeqState::RCV_STATUS, 0, 0},
|
||||
{SeqState::RCV_MESSAGE, 0, 0},
|
||||
{SeqState::CMD_COMPLETE, 0, INTSTAT_SR}
|
||||
};
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
|
||||
ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str());
|
||||
}
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = complete_steps_desc;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->cur_state = SeqState::RCV_STATUS;
|
||||
this->sequencer();
|
||||
break;
|
||||
case CMD_MSG_ACCEPTED:
|
||||
// Don't release ACK if ATN is asserted.
|
||||
// Executing this command with ATN true means that
|
||||
// the initiator wants to reject the current message.
|
||||
// That should be recognized and handled by the target.
|
||||
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN))
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_XFER_PAD_BYTES:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
|
||||
ABORT_F("%s: unsupported phase %d in CMD_XFER_PAD_BYTES",
|
||||
this->name.c_str(), this->bus_obj->current_phase());
|
||||
std::memset(this->data_fifo, 0, DATA_FIFO_MAX);
|
||||
// FIXME: does the non-DMA version of this command use the transfer counter?
|
||||
this->data_fifo_pos = std::min((int)this->set_xfer_count, DATA_FIFO_MAX);
|
||||
this->cur_state = SeqState::SEND_CMD;
|
||||
this->sequencer();
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND) {
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
}
|
||||
break;
|
||||
case CMD_RESET_ATN:
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_SELECT_NO_ATN:
|
||||
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
static SeqDesc * sel_no_atn_desc = new SeqDesc[2]{
|
||||
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
|
||||
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->seq_step = this->cur_step = 0;
|
||||
this->cmd_steps = sel_no_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "%s: SELECT W/O ATN command started", this->name.c_str());
|
||||
break;
|
||||
case CMD_SELECT_WITH_ATN:
|
||||
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
static SeqDesc * sel_with_atn_desc = new SeqDesc[3]{
|
||||
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG, INTSTAT_SR | INTSTAT_SO},
|
||||
{2, ScsiPhase::COMMAND, SeqState::SEND_CMD, INTSTAT_SR | INTSTAT_SO},
|
||||
{4, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->seq_step = this->cur_step = 0;
|
||||
this->bytes_out = 1; // set message length
|
||||
this->cmd_steps = sel_with_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "%s: SELECT WITH ATN command started", this->name.c_str());
|
||||
break;
|
||||
case CMD_SELECT_WITH_ATN_AND_STOP:
|
||||
static SeqDesc * sel_with_atn_stop_desc = new SeqDesc[3]{
|
||||
{0, ScsiPhase::MESSAGE_OUT, SeqState::SEND_MSG_EX, INTSTAT_SR | INTSTAT_SO},
|
||||
{1, -1, SeqState::CMD_COMPLETE, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = this->cur_step = 0;
|
||||
this->bytes_out = 1; // set message length
|
||||
this->cmd_steps = sel_with_atn_stop_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "%s: SELECT WITH ATN AND STOP command started", this->name.c_str());
|
||||
break;
|
||||
case CMD_ENA_SEL_RESEL:
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -396,7 +443,7 @@ uint8_t Sc53C94::fifo_pop()
|
||||
} else {
|
||||
data = this->data_fifo[0];
|
||||
this->data_fifo_pos--;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
std::memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -404,13 +451,29 @@ uint8_t Sc53C94::fifo_pop()
|
||||
|
||||
void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
if (this->seq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->seq_timer_id = 0;
|
||||
}
|
||||
|
||||
if (delay_ns) {
|
||||
this->seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
} else {
|
||||
this->seq_timer_id = TimerManager::get_instance()->add_immediate_timer(
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::sequencer()
|
||||
@@ -440,7 +503,7 @@ void Sc53C94::sequencer()
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->my_bus_id)) { // arbitration won
|
||||
this->next_state = this->cmd_steps->next_step;
|
||||
this->next_state = SeqState::SEL_BEGIN;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "%s: arbitration lost!", this->name.c_str());
|
||||
@@ -461,8 +524,8 @@ void Sc53C94::sequencer()
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "%s: selection completed", this->name.c_str());
|
||||
} else { // selection timeout
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status = this->cmd_steps->status;
|
||||
this->seq_step = 0;
|
||||
this->int_status = INTSTAT_DIS;
|
||||
this->bus_obj->disconnect(this->my_bus_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
@@ -470,27 +533,31 @@ void Sc53C94::sequencer()
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
case SeqState::SEND_MSG_EX:
|
||||
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
|
||||
this->drq_cb(1);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->update_irq();
|
||||
break;
|
||||
if (this->drq_cb)
|
||||
this->drq_cb(1);
|
||||
} else {
|
||||
this->bus_obj->target_xfer_data();
|
||||
if (this->cur_state == SeqState::SEND_MSG_EX) {
|
||||
this->notify(ScsiNotification::BUS_PHASE_CHANGE, ScsiPhase::MESSAGE_OUT);
|
||||
} else {
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
|
||||
if (this->cmd_steps)
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
}
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
if (this->data_fifo_pos < 1 && this->is_dma_cmd) {
|
||||
this->drq_cb(1);
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
break;
|
||||
}
|
||||
this->bus_obj->target_xfer_data();
|
||||
if (this->drq_cb)
|
||||
this->drq_cb(1);
|
||||
} else
|
||||
this->bus_obj->target_xfer_data();
|
||||
break;
|
||||
case SeqState::CMD_COMPLETE:
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status = this->cmd_steps->status;
|
||||
this->int_status = INTSTAT_SR | INTSTAT_SO;
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -498,8 +565,8 @@ void Sc53C94::sequencer()
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->is_dma_cmd) {
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
|
||||
this->channel_obj->xfer_retry();
|
||||
break;
|
||||
}
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
@@ -508,6 +575,10 @@ void Sc53C94::sequencer()
|
||||
this->sequencer();
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
if (this->is_dma_cmd && this->channel_obj->is_ready()) {
|
||||
this->channel_obj->xfer_retry();
|
||||
break;
|
||||
}
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
@@ -515,6 +586,18 @@ void Sc53C94::sequencer()
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->cur_state = (this->cur_bus_phase == ScsiPhase::MESSAGE_OUT) ?
|
||||
SeqState::SEND_MSG : SeqState::RCV_MESSAGE;
|
||||
this->sequencer();
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported phase %d in XFER_BEGIN", this->name.c_str(),
|
||||
this->cur_bus_phase);
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
@@ -522,6 +605,7 @@ void Sc53C94::sequencer()
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -544,11 +628,17 @@ void Sc53C94::sequencer()
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_STATUS) {
|
||||
this->bus_obj->target_next_step();
|
||||
if (this->cur_bus_phase == ScsiPhase::MESSAGE_IN) {
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_REQ);
|
||||
this->cur_state = SeqState::RCV_MESSAGE;
|
||||
this->sequencer();
|
||||
}
|
||||
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
if (this->cur_cmd == CMD_COMPLETE_STEPS) {
|
||||
this->cur_state = SeqState::CMD_COMPLETE;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -562,36 +652,51 @@ void Sc53C94::update_irq()
|
||||
uint8_t new_irq = !!(this->int_status != 0);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->status = (this->status & 0x7F) | (new_irq << 7);
|
||||
this->status = (this->status & ~STAT_INT) | (new_irq << 7);
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
void Sc53C94::notify(ScsiNotification notif_type, int param)
|
||||
{
|
||||
switch (msg_type) {
|
||||
case ScsiMsg::CONFIRM_SEL:
|
||||
switch (notif_type) {
|
||||
case ScsiNotification::CONFIRM_SEL:
|
||||
if (this->target_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
|
||||
LOG_F(WARNING, "%s: invalid selection confirmation message ignored",
|
||||
this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case ScsiMsg::BUS_PHASE_CHANGE:
|
||||
case ScsiNotification::BUS_PHASE_CHANGE:
|
||||
this->cur_bus_phase = param;
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
if (param == ScsiPhase::BUS_FREE) { // target want to disconnect
|
||||
this->int_status = INTSTAT_DIS;
|
||||
this->update_irq();
|
||||
this->cur_state = SeqState::IDLE;
|
||||
}
|
||||
if (this->cmd_steps != nullptr) {
|
||||
if (this->cur_bus_phase == this->cmd_steps->expected_phase) {
|
||||
this->next_state = this->cmd_steps->next_state;
|
||||
this->cmd_steps++;
|
||||
this->seq_defer_state(0);
|
||||
} else {
|
||||
this->cur_step = this->cmd_steps->step_num;
|
||||
this->seq_step = this->cur_step;
|
||||
this->int_status = this->cmd_steps->status;
|
||||
this->update_irq();
|
||||
if (this->cmd_steps->next_state == SeqState::CMD_COMPLETE)
|
||||
this->exec_next_command();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
|
||||
msg_type);
|
||||
notif_type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,8 +716,7 @@ int Sc53C94::send_data(uint8_t* dst_ptr, int count)
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
|
||||
} else if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
ABORT_F("%s: don't know what to do next!", this->name.c_str());
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
@@ -643,7 +747,7 @@ void Sc53C94::real_dma_xfer_out()
|
||||
{
|
||||
// transfer data from host's memory to target
|
||||
|
||||
while (this->xfer_count) {
|
||||
if (this->xfer_count) {
|
||||
uint32_t got_bytes;
|
||||
uint8_t* src_ptr;
|
||||
this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX),
|
||||
@@ -660,6 +764,16 @@ void Sc53C94::real_dma_xfer_out()
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->xfer_count) {
|
||||
this->dma_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10000,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->dma_timer_id = 0;
|
||||
this->real_dma_xfer_out();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::real_dma_xfer_in()
|
||||
@@ -668,25 +782,141 @@ void Sc53C94::real_dma_xfer_in()
|
||||
|
||||
// transfer data from target to host's memory
|
||||
|
||||
while (this->xfer_count) {
|
||||
if (this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
if (this->xfer_count && this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
this->dma_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10000,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->dma_timer_id = 0;
|
||||
this->real_dma_xfer_in();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::dma_wait() {
|
||||
if (this->cur_bus_phase == ScsiPhase::DATA_IN && this->cur_state == SeqState::RCV_DATA) {
|
||||
real_dma_xfer_in();
|
||||
}
|
||||
else if (this->cur_bus_phase == ScsiPhase::DATA_OUT && this->cur_state == SeqState::SEND_DATA) {
|
||||
real_dma_xfer_out();
|
||||
}
|
||||
else {
|
||||
this->dma_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
10000,
|
||||
[this]() {
|
||||
this->dma_timer_id = 0;
|
||||
this->dma_wait();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::dma_start()
|
||||
{
|
||||
dma_wait();
|
||||
}
|
||||
|
||||
void Sc53C94::dma_stop()
|
||||
{
|
||||
if (this->dma_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->dma_timer_id);
|
||||
this->dma_timer_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Sc53C94::xfer_from(uint8_t *buf, int len) {
|
||||
int bytes_moved = 0;
|
||||
|
||||
if (this->cur_cmd != CMD_XFER || !this->is_dma_cmd ||
|
||||
this->cur_bus_phase != ScsiPhase::DATA_IN) {
|
||||
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
|
||||
return bytes_moved;
|
||||
}
|
||||
|
||||
len = std::min(len, (int)(this->xfer_count));
|
||||
|
||||
if (this->data_fifo_pos) {
|
||||
int fifo_bytes = std::min(this->data_fifo_pos, len);
|
||||
std::memcpy(buf, this->data_fifo, fifo_bytes);
|
||||
this->data_fifo_pos -= fifo_bytes;
|
||||
this->xfer_count -= fifo_bytes;
|
||||
bytes_moved += fifo_bytes;
|
||||
buf += fifo_bytes;
|
||||
if (!this->xfer_count) {
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
return bytes_moved;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->bus_obj->pull_data(this->target_id, buf, this->xfer_count)) {
|
||||
bytes_moved += this->xfer_count;
|
||||
this->xfer_count = 0;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
return bytes_moved;
|
||||
}
|
||||
|
||||
int Sc53C94::xfer_to(uint8_t *buf, int len) {
|
||||
int bytes_moved = 0;
|
||||
|
||||
if (!this->xfer_count || !this->is_dma_cmd) {
|
||||
LOG_F(9, "%s: ignoring DMA data transfer request", this->name.c_str());
|
||||
return bytes_moved;
|
||||
}
|
||||
|
||||
len = std::min(len, (int)(this->xfer_count));
|
||||
|
||||
// Being in the DATA_OUT phase means that we're about to move
|
||||
// a big chunk of data. The real device uses its FIFO as buffer.
|
||||
// For simplicity, the code below transfers the whole chunk at once.
|
||||
// This can be broken into smaller chunks later if desired.
|
||||
if (this->cur_bus_phase == ScsiPhase::DATA_OUT) {
|
||||
if (this->bus_obj->push_data(this->target_id, buf, len)) {
|
||||
this->xfer_count -= len;
|
||||
bytes_moved += len;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
len = 0;
|
||||
} else
|
||||
LOG_F(WARNING, "%s: xfer_to failed to transfer data", this->name.c_str());
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
if (this->xfer_count) {
|
||||
// fill in the data FIFO first
|
||||
uint32_t fifo_bytes = std::min(len, DATA_FIFO_MAX - this->data_fifo_pos);
|
||||
std::memcpy(&this->data_fifo[this->data_fifo_pos], buf, fifo_bytes);
|
||||
this->data_fifo_pos += fifo_bytes;
|
||||
this->xfer_count -= fifo_bytes;
|
||||
bytes_moved += fifo_bytes;
|
||||
if (!this->xfer_count) {
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
return bytes_moved;
|
||||
}
|
||||
|
||||
static const PropMap Sc53C94_properties = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -30,16 +30,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define SC_53C94_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class DmaBidirChannel;
|
||||
class InterruptCtrl;
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
|
||||
/** 53C94 read registers */
|
||||
namespace Read {
|
||||
enum Reg53C94 : uint8_t {
|
||||
@@ -96,9 +94,9 @@ enum {
|
||||
CMD_XFER = 0x10,
|
||||
CMD_COMPLETE_STEPS = 0x11,
|
||||
CMD_MSG_ACCEPTED = 0x12,
|
||||
//CMD_TRANSFER_PAD_BYTES = 0x18,
|
||||
CMD_XFER_PAD_BYTES = 0x18,
|
||||
CMD_SET_ATN = 0x1A, // no interrupt
|
||||
//CMD_RESET_ATN = 0x1B, // no interrupt
|
||||
CMD_RESET_ATN = 0x1B, // no interrupt
|
||||
|
||||
// Target commands
|
||||
//CMD_SEND_MESSAGE = 0x20,
|
||||
@@ -113,13 +111,13 @@ enum {
|
||||
//CMD_RECEIVE_DATA = 0x2A,
|
||||
//CMD_RECEIVE_COMMAND_STEPS = 0x2B,
|
||||
CMD_DMA_STOP = 0x04, // no interrupt
|
||||
CMD_ACCESS_FIFO_COMMAND = 0x05,
|
||||
//CMD_ACCESS_FIFO_COMMAND = 0x05,
|
||||
|
||||
// Idle Commands
|
||||
//CMD_RESELECT_STEPS = 0x40,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_SELECT_WITH_ATN = 0x42,
|
||||
//CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
|
||||
CMD_SELECT_WITH_ATN_AND_STOP = 0x43,
|
||||
CMD_ENA_SEL_RESEL = 0x44, // no interrupt
|
||||
//CMD_DISABLE_SEL_RESEL = 0x45,
|
||||
//CMD_SELECT_WITH_ATN3_STEPS = 0x46,
|
||||
@@ -130,14 +128,12 @@ enum {
|
||||
CMD_ISDMA = 0x80,
|
||||
};
|
||||
|
||||
/** Status register bits. **/
|
||||
/** Status register bits. */
|
||||
enum {
|
||||
//SCSI_CTRL_IO = 0x01, // Input/Output
|
||||
//SCSI_CTRL_CD = 0x02, // Command/Data
|
||||
//SCSI_CTRL_MSG = 0x04, // Message
|
||||
//STAT_GCV = 0x08, // Group Code Valid
|
||||
STAT_PHASE_MASK = 0x07, // mask for I/O, Command and Message bits
|
||||
STAT_GCV = 0x08, // Group Code Valid
|
||||
STAT_TC = 0x10, // Terminal count (NCR) / count to zero (AMD)
|
||||
//STAT_PE = 0x20, // Parity Error
|
||||
STAT_PE = 0x20, // Parity Error
|
||||
STAT_GE = 0x40, // Gross Error (NCR) / Illegal Operation Error (AMD)
|
||||
STAT_INT = 0x80, // Interrupt
|
||||
};
|
||||
@@ -154,6 +150,12 @@ enum {
|
||||
INTSTAT_SEL = 0x01, // selected as a target without attention
|
||||
};
|
||||
|
||||
/** Configuration register 1 bits. */
|
||||
enum {
|
||||
CFG1_DISR = 0x40, // disable interrupt on SCSI reset
|
||||
};
|
||||
|
||||
/** Configuration register 2 bits. */
|
||||
enum {
|
||||
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
|
||||
};
|
||||
@@ -168,6 +170,7 @@ namespace SeqState {
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_MSG_EX,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
@@ -179,16 +182,19 @@ namespace SeqState {
|
||||
};
|
||||
};
|
||||
|
||||
/** Sequence descriptor for sequencer commands. */
|
||||
constexpr auto DATA_FIFO_MAX = 16;
|
||||
|
||||
/** Sequence descriptor for multistep commands. */
|
||||
typedef struct {
|
||||
int next_step;
|
||||
int step_num;
|
||||
int expected_phase;
|
||||
int next_state;
|
||||
int status;
|
||||
} SeqDesc;
|
||||
|
||||
typedef std::function<void(const uint8_t drq_state)> DrqCb;
|
||||
|
||||
class Sc53C94 : public ScsiDevice {
|
||||
class Sc53C94 : public ScsiDevice, public DmaDevice {
|
||||
public:
|
||||
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
|
||||
~Sc53C94() = default;
|
||||
@@ -198,7 +204,7 @@ public:
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
int device_postinit() override;
|
||||
|
||||
// 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
@@ -210,8 +216,18 @@ public:
|
||||
void real_dma_xfer_out();
|
||||
void real_dma_xfer_in();
|
||||
|
||||
void dma_start();
|
||||
void dma_wait();
|
||||
void dma_stop();
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
auto dbdma_ch = dynamic_cast<DMAChannel*>(dma_ch);
|
||||
if (dbdma_ch) {
|
||||
dbdma_ch->set_callbacks(
|
||||
std::bind(&Sc53C94::dma_start, this),
|
||||
std::bind(&Sc53C94::dma_stop, this)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
void set_drq_callback(DrqCb cb) {
|
||||
@@ -219,12 +235,19 @@ public:
|
||||
}
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool get_more_data() { return false; };
|
||||
bool has_data() { return this->data_fifo_pos != 0; };
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
void process_command() {};
|
||||
void notify(ScsiNotification notif_type, int param) override;
|
||||
bool prepare_data() override { return false; };
|
||||
bool get_more_data() override { return false; };
|
||||
bool has_data() override { return this->data_fifo_pos != 0; };
|
||||
int send_data(uint8_t* dst_ptr, int count) override;
|
||||
void process_command() override {};
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len) override;
|
||||
int xfer_to(uint8_t *buf, int len) override;
|
||||
int tell_xfer_size() override {
|
||||
return this->xfer_count;
|
||||
};
|
||||
|
||||
protected:
|
||||
void reset_device();
|
||||
@@ -244,11 +267,10 @@ protected:
|
||||
private:
|
||||
uint8_t chip_id = 0;
|
||||
uint8_t my_bus_id = 0;
|
||||
ScsiBus* bus_obj;
|
||||
uint32_t my_timer_id = 0;
|
||||
|
||||
uint8_t cmd_fifo[2];
|
||||
uint8_t data_fifo[16];
|
||||
uint8_t data_fifo[DATA_FIFO_MAX];
|
||||
int cmd_fifo_pos = 0;
|
||||
int data_fifo_pos = 0;
|
||||
int bytes_out = 0;
|
||||
@@ -260,6 +282,7 @@ private:
|
||||
uint8_t int_status = 0;
|
||||
uint8_t seq_step = 0;
|
||||
uint8_t sel_timeout = 0;
|
||||
uint8_t sync_period = 5;
|
||||
uint8_t sync_offset = 0;
|
||||
uint8_t clk_factor = 0;
|
||||
uint8_t config1 = 0;
|
||||
@@ -275,15 +298,17 @@ private:
|
||||
uint8_t cur_cmd = 0;
|
||||
bool is_dma_cmd = false;
|
||||
int cur_bus_phase = 0;
|
||||
uint8_t cur_step = 0; // internal step counter for multistep commands
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint64_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch = nullptr;
|
||||
DrqCb drq_cb = nullptr;
|
||||
uint32_t dma_timer_id = 0;
|
||||
};
|
||||
|
||||
#endif // SC_53C94_H
|
||||
+52
-27
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,6 +47,7 @@ enum {
|
||||
SCSI_CTRL_RST = 1 << 15,
|
||||
};
|
||||
|
||||
/** SCSI bus phases. */
|
||||
namespace ScsiPhase {
|
||||
enum : int {
|
||||
BUS_FREE = 0,
|
||||
@@ -63,6 +64,7 @@ namespace ScsiPhase {
|
||||
};
|
||||
};
|
||||
|
||||
/** SCSI status codes. */
|
||||
namespace ScsiStatus {
|
||||
enum : uint8_t {
|
||||
GOOD = 0,
|
||||
@@ -70,6 +72,7 @@ namespace ScsiStatus {
|
||||
};
|
||||
};
|
||||
|
||||
/** Standard message codes. */
|
||||
namespace ScsiMessage {
|
||||
enum : uint8_t {
|
||||
COMMAND_COMPLETE = 0,
|
||||
@@ -82,13 +85,19 @@ namespace ScsiMessage {
|
||||
};
|
||||
};
|
||||
|
||||
enum ScsiMsg : int {
|
||||
/** Extended message codes. */
|
||||
namespace ScsiExtMessage {
|
||||
enum : uint8_t {
|
||||
MODIFY_DATA_PTR = 0,
|
||||
SYNCH_XFER_REQ = 1,
|
||||
WIDE_XFER_REQ = 3,
|
||||
};
|
||||
};
|
||||
|
||||
/** Internal notification codes for our SCSI implementation. */
|
||||
enum ScsiNotification : int {
|
||||
CONFIRM_SEL = 1,
|
||||
BUS_PHASE_CHANGE,
|
||||
SEND_CMD_BEGIN,
|
||||
SEND_CMD_END,
|
||||
MESSAGE_BEGIN,
|
||||
MESSAGE_END,
|
||||
};
|
||||
|
||||
enum ScsiCommand : uint8_t {
|
||||
@@ -142,27 +151,28 @@ enum ScsiSense : int {
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
SAVING_NOT_SUPPORTED = 0x39,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
#define BUS_SETTLE_DELAY 400
|
||||
#define BUS_FREE_DELAY 800
|
||||
#define BUS_CLEAR_DELAY 800
|
||||
#define ARB_DELAY 2400
|
||||
#define SEL_ABORT_TIME 200000
|
||||
#define SEL_TIME_OUT 250000000
|
||||
constexpr uint64_t BUS_SETTLE_DELAY = 400;
|
||||
constexpr uint64_t BUS_FREE_DELAY = 800;
|
||||
constexpr uint64_t BUS_CLEAR_DELAY = 800;
|
||||
constexpr uint64_t ARB_DELAY = 2400;
|
||||
constexpr uint64_t SEL_ABORT_TIME = 200000;
|
||||
constexpr uint64_t SEL_TIME_OUT = 250000000;
|
||||
|
||||
#define SCSI_MAX_DEVS 8
|
||||
constexpr auto SCSI_MAX_DEVS = 8;
|
||||
|
||||
class ScsiBus;
|
||||
|
||||
@@ -179,10 +189,11 @@ public:
|
||||
};
|
||||
~ScsiDevice() = default;
|
||||
|
||||
virtual void notify(ScsiMsg msg_type, int param);
|
||||
virtual void notify(ScsiNotification notif_type, int param);
|
||||
virtual void next_step();
|
||||
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
|
||||
virtual void switch_phase(const int new_phase);
|
||||
virtual bool allow_phase_change();
|
||||
|
||||
virtual bool has_data() { return this->data_size != 0; };
|
||||
virtual int xfer_data();
|
||||
@@ -194,11 +205,14 @@ public:
|
||||
virtual bool prepare_data() = 0;
|
||||
virtual bool get_more_data() = 0;
|
||||
virtual void process_command() = 0;
|
||||
virtual void process_message();
|
||||
|
||||
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
|
||||
this->bus_obj = bus_obj_ptr;
|
||||
}
|
||||
|
||||
void report_error(uint8_t sense_key, uint8_t asc);
|
||||
|
||||
protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
@@ -221,6 +235,8 @@ protected:
|
||||
uint8_t last_selection_message = 0;
|
||||
ScsiBus* bus_obj;
|
||||
|
||||
int *seq_steps = nullptr;
|
||||
|
||||
action_callback pre_xfer_action = nullptr;
|
||||
action_callback post_xfer_action = nullptr;
|
||||
};
|
||||
@@ -243,9 +259,18 @@ public:
|
||||
|
||||
// low-level state management
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
int get_initiator_id() { return this->initiator_id; };
|
||||
int get_target_id() { return this->target_id; };
|
||||
|
||||
int current_phase() const {
|
||||
return this->cur_phase;
|
||||
}
|
||||
|
||||
int get_initiator_id() const {
|
||||
return this->initiator_id;
|
||||
}
|
||||
|
||||
int get_target_id() const {
|
||||
return this->target_id;
|
||||
}
|
||||
|
||||
// reading/writing control lines
|
||||
void assert_ctrl_line(int id, uint16_t mask);
|
||||
|
||||
@@ -52,7 +52,7 @@ ScsiBus::ScsiBus(const std::string name)
|
||||
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
|
||||
{
|
||||
if (this->devices[id] != nullptr) {
|
||||
ABORT_F("ScsiBus: device with ID %d already registered", id);
|
||||
ABORT_F("%s: device with ID %d already registered", this->get_name().c_str(), id);
|
||||
}
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
@@ -66,14 +66,17 @@ void ScsiBus::change_bus_phase(int initiator_id)
|
||||
if (i == initiator_id)
|
||||
continue; // don't notify the initiator
|
||||
if (this->devices[i] != nullptr) {
|
||||
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
this->devices[i]->notify(ScsiNotification::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
{
|
||||
DCHECK_F(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS, "ScsiBus: invalid initiator ID %d", initiator_id);
|
||||
if (!(initiator_id >= 0 && initiator_id < SCSI_MAX_DEVS)) {
|
||||
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), initiator_id);
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t new_state = 0xFFFFU & mask;
|
||||
|
||||
@@ -92,7 +95,9 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
|
||||
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
|
||||
{
|
||||
DCHECK_F(id >= 0 && id < SCSI_MAX_DEVS, "ScsiBus: invalid initiator ID %d", id);
|
||||
if (!(id >= 0 && id < SCSI_MAX_DEVS)) {
|
||||
LOG_F(ERROR, "%s: invalid initiator ID %d", this->get_name().c_str(), id);
|
||||
}
|
||||
|
||||
uint16_t new_state = 0;
|
||||
|
||||
@@ -237,7 +242,7 @@ void ScsiBus::confirm_selection(int target_id)
|
||||
|
||||
// notify initiator about selection confirmation from target
|
||||
if (this->initiator_id >= 0) {
|
||||
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
|
||||
this->devices[this->initiator_id]->notify(ScsiNotification::CONFIRM_SEL, target_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +259,7 @@ bool ScsiBus::pull_data(const int id, uint8_t* dst_ptr, const int size)
|
||||
}
|
||||
|
||||
if (!this->devices[id]->send_data(dst_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring T->I data!");
|
||||
LOG_F(ERROR, "%s: error while transferring T->I data!", this->get_name().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -263,11 +268,19 @@ bool ScsiBus::pull_data(const int id, uint8_t* dst_ptr, const int size)
|
||||
|
||||
bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
|
||||
{
|
||||
if (!this->devices[id]->rcv_data(src_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring I->T data!");
|
||||
if (!this->devices[id]) {
|
||||
LOG_F(ERROR, "%s: no device %d for push_data %d bytes",
|
||||
this->get_name().c_str(), id, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->devices[id]->rcv_data(src_ptr, size)) {
|
||||
if (size) {
|
||||
LOG_F(ERROR, "%s: error while transferring I->T data!", this->get_name().c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -277,12 +290,22 @@ int ScsiBus::target_xfer_data() {
|
||||
|
||||
void ScsiBus::target_next_step()
|
||||
{
|
||||
this->devices[this->target_id]->next_step();
|
||||
if (target_id < 0) {
|
||||
LOG_F(ERROR, "%s: target_id is not set yet.", this->get_name().c_str());
|
||||
}
|
||||
else {
|
||||
this->devices[this->target_id]->next_step();
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
|
||||
{
|
||||
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
|
||||
if (target_id < 0) {
|
||||
LOG_F(ERROR, "%s: target_id is not set yet.", this->get_name().c_str());
|
||||
}
|
||||
else {
|
||||
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -307,17 +330,22 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we skip ID 3.
|
||||
for (scsi_id = 0; scsi_id < SCSI_MAX_DEVS * 2 && (scsi_id == 3 || this->devices[scsi_id % SCSI_MAX_DEVS]); scsi_id++) {}
|
||||
for (scsi_id = 0; scsi_id < SCSI_MAX_DEVS * 2 && (scsi_id == 3 ||
|
||||
this->devices[scsi_id % SCSI_MAX_DEVS]); scsi_id++) {}
|
||||
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiHD" + bus_suffix + "," + std::to_string(scsi_id);
|
||||
std::string scsi_device_name = "ScsiHD" + bus_suffix + "," +
|
||||
std::to_string(scsi_id);
|
||||
ScsiHardDisk *scsi_device = new ScsiHardDisk(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name, std::unique_ptr<ScsiHardDisk>(scsi_device));
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiHardDisk>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. HDD \"%s\" was not added.", this->get_name().c_str(), path.c_str());
|
||||
LOG_F(ERROR, "%s: Too many devices. HDD \"%s\" was not added.",
|
||||
this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,17 +355,22 @@ void ScsiBus::attach_scsi_devices(const std::string bus_suffix)
|
||||
std::istringstream image_stream(image_path);
|
||||
while (std::getline(image_stream, path, ':')) {
|
||||
// do two passes because we start at ID 3.
|
||||
for (scsi_id = 3; scsi_id < SCSI_MAX_DEVS * 2 && this->devices[scsi_id % SCSI_MAX_DEVS]; scsi_id++) {}
|
||||
for (scsi_id = 3; scsi_id < SCSI_MAX_DEVS * 2 &&
|
||||
this->devices[scsi_id % SCSI_MAX_DEVS]; scsi_id++) {}
|
||||
|
||||
if (scsi_id < SCSI_MAX_DEVS * 2) {
|
||||
scsi_id = scsi_id % SCSI_MAX_DEVS;
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," + std::to_string(scsi_id);
|
||||
std::string scsi_device_name = "ScsiCdrom" + bus_suffix + "," +
|
||||
std::to_string(scsi_id);
|
||||
ScsiCdrom *scsi_device = new ScsiCdrom(scsi_device_name, scsi_id);
|
||||
gMachineObj->add_device(scsi_device_name, std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
gMachineObj->add_device(scsi_device_name,
|
||||
std::unique_ptr<ScsiCdrom>(scsi_device));
|
||||
this->register_device(scsi_id, scsi_device);
|
||||
scsi_device->insert_image(path);
|
||||
}
|
||||
else {
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.", this->get_name().c_str(), path.c_str());
|
||||
LOG_F(ERROR, "%s: Too many devices. CD-ROM \"%s\" was not added.",
|
||||
this->get_name().c_str(), path.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,4 +385,4 @@ static const DeviceDescription ScsiMesh_Descriptor = {
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ScsiCurio, ScsiCurio_Descriptor);
|
||||
REGISTER_DEVICE(ScsiMesh, ScsiMesh_Descriptor);
|
||||
REGISTER_DEVICE(ScsiMesh, ScsiMesh_Descriptor);
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsibusctrl.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
using namespace Scsi_Bus_Controller;
|
||||
|
||||
void ScsiBusController::seq_defer_state(uint64_t delay_ns) {
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
}
|
||||
|
||||
void ScsiBusController::sequencer() {
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "%s: arbitration error, bus not free!", this->name.c_str());
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
this->step_completed();
|
||||
} else { // arbitration lost
|
||||
LOG_F(ERROR, "%s: arbitration lost!", this->name.c_str());
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->report_error(ARB_LOST);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->assert_atn);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "%s: selection completed", this->name.c_str());
|
||||
this->step_completed();
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->report_error(SEL_TIMEOUT);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
if (this->fifo_pos) {
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
|
||||
if (this->to_xfer <= 0)
|
||||
this->step_completed();
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
this->bus_obj->target_xfer_data();
|
||||
if (!this->fifo_pos)
|
||||
this->step_completed();
|
||||
break;
|
||||
case SeqState::XFER_BEGIN:
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
if (this->is_initiator)
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
break;
|
||||
case SeqState::SEND_DATA:
|
||||
if (this->bus_obj->push_data(this->dst_id, this->data_fifo, this->fifo_pos)) {
|
||||
this->to_xfer -= this->fifo_pos;
|
||||
this->fifo_pos = 0;
|
||||
if (this->to_xfer <= 0) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_DATA:
|
||||
// check for unexpected bus phase changes
|
||||
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
|
||||
LOG_F(WARNING, "%s: phase mismatch!", this->name.c_str());
|
||||
} else {
|
||||
if (!this->rcv_data()) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_STATUS:
|
||||
case SeqState::RCV_MESSAGE:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_MESSAGE)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
this->cur_state = SeqState::IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unimplemented sequencer state %d", this->name.c_str(),
|
||||
this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBusController::notify(ScsiNotification notif_type, int param) {
|
||||
switch (notif_type) {
|
||||
case ScsiNotification::CONFIRM_SEL:
|
||||
if (this->dst_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
|
||||
this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case ScsiNotification::BUS_PHASE_CHANGE:
|
||||
this->cur_bus_phase = param;
|
||||
#if 0
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
|
||||
notif_type);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBusController::rcv_data() {
|
||||
int req_count;
|
||||
|
||||
// return if REQ line is negated
|
||||
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_REQ)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->to_xfer)
|
||||
return false;
|
||||
|
||||
req_count = std::min(this->to_xfer, DATA_FIFO_DEPTH - this->fifo_pos);
|
||||
|
||||
this->bus_obj->pull_data(this->dst_id, &this->data_fifo[this->fifo_pos], req_count);
|
||||
this->fifo_pos += req_count;
|
||||
this->to_xfer -= req_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiBusController::send_data(uint8_t* dst_ptr, int count) {
|
||||
if (dst_ptr == nullptr || !count)
|
||||
return 0;
|
||||
|
||||
int actual_count = std::min(this->fifo_pos, count);
|
||||
|
||||
// move data out of the data FIFO
|
||||
std::memcpy(dst_ptr, this->data_fifo, actual_count);
|
||||
|
||||
// remove the just readed data from the data FIFO
|
||||
this->fifo_pos -= actual_count;
|
||||
this->to_xfer -= actual_count;
|
||||
if (this->fifo_pos > 0)
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->fifo_pos);
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
int ScsiBusController::xfer_from(uint8_t *buf, int len) {
|
||||
if (len > this->to_xfer + this->fifo_pos)
|
||||
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
|
||||
|
||||
if (this->fifo_pos) {
|
||||
int fifo_bytes = std::min(this->fifo_pos, len);
|
||||
std::memcpy(buf, this->data_fifo, fifo_bytes);
|
||||
this->fifo_pos -= fifo_bytes;
|
||||
len -= fifo_bytes;
|
||||
buf += fifo_bytes;
|
||||
}
|
||||
|
||||
int dma_bytes = std::min(this->to_xfer, len);
|
||||
|
||||
if (this->bus_obj->pull_data(this->dst_id, buf, dma_bytes)) {
|
||||
this->to_xfer -= dma_bytes;
|
||||
if (this->to_xfer <= 0) {
|
||||
this->xfer_count = this->to_xfer;
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void ScsiBusController::update_irq() {
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBusController::fifo_push(const uint8_t data) {
|
||||
if (this->fifo_pos < DATA_FIFO_DEPTH) {
|
||||
this->data_fifo[this->fifo_pos++] = data;
|
||||
if (!this->xfer_count)
|
||||
LOG_F(WARNING, "%s: zero xfer_count!", this->name.c_str());
|
||||
if (--this->xfer_count == 0)
|
||||
this->sequencer();
|
||||
} else
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
uint8_t ScsiBusController::fifo_pop() {
|
||||
uint8_t data = 0;
|
||||
|
||||
if (this->fifo_pos) {
|
||||
data = this->data_fifo[0];
|
||||
if (--this->fifo_pos)
|
||||
std::memmove(this->data_fifo, &this->data_fifo[1], this->fifo_pos);
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->fifo_pos)
|
||||
this->sequencer();
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-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/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus controller definitions. */
|
||||
|
||||
#ifndef SCSI_BUS_CTRL_H
|
||||
#define SCSI_BUS_CTRL_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
namespace Scsi_Bus_Controller {
|
||||
/** SCSI sequencer states. */
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
|
||||
/** Sequencer error codes. */
|
||||
enum : int {
|
||||
ARB_LOST = 1,
|
||||
SEL_TIMEOUT,
|
||||
};
|
||||
|
||||
constexpr auto DATA_FIFO_DEPTH = 16;
|
||||
|
||||
class ScsiBusController : public ScsiDevice, public DmaDevice {
|
||||
public:
|
||||
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
}
|
||||
~ScsiBusController() = default;
|
||||
|
||||
// implements SCSI FSM
|
||||
void sequencer();
|
||||
|
||||
virtual void step_completed() = 0;
|
||||
virtual void report_error(const int error) = 0;
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiNotification notif_type, int param) override;
|
||||
bool prepare_data() override { return false; };
|
||||
bool get_more_data() override { return false; };
|
||||
bool has_data() override { return false; };
|
||||
bool rcv_data();
|
||||
int send_data(uint8_t* dst_ptr, int count) override;
|
||||
void process_command() override {};
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len) override;
|
||||
|
||||
protected:
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void update_irq();
|
||||
void fifo_push(const uint8_t data);
|
||||
uint8_t fifo_pop();
|
||||
|
||||
ScsiBus* bus_obj = nullptr;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
bool is_dma_cmd = false;
|
||||
bool is_initiator = true;
|
||||
bool assert_atn = false;
|
||||
|
||||
// Data FIFO state
|
||||
int fifo_pos = 0;
|
||||
int to_xfer = 0;
|
||||
uint32_t xfer_count = 0;
|
||||
int bytes_out = 0;
|
||||
uint8_t data_fifo[DATA_FIFO_DEPTH] = {};
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id = 0;
|
||||
uint32_t cur_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
uint32_t next_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
int cur_bus_phase = 0;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint64_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
uint8_t int_mask = 0;
|
||||
uint8_t int_stat = 0;
|
||||
};
|
||||
|
||||
#endif // SCSI_BUS_CTRL_H
|
||||
@@ -32,19 +32,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
static char cdrom_vendor_sony_id[] = "SONY ";
|
||||
static char cdu8003a_product_id[] = "CD-ROM CDU-8003A";
|
||||
static char cdu8003a_revision_id[] = "1.9a";
|
||||
|
||||
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
|
||||
{
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->report_error(sense_key, asc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
{
|
||||
uint32_t lba, xfer_len;
|
||||
uint32_t lba;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
@@ -61,55 +60,20 @@ void ScsiCdrom::process_command()
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->read(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
this->bytes_out = this->inquiry(cmd, this->data_buf);
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
this->incoming_size = cmd[4];
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
this->mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (cmd[4] & 1) == 0;
|
||||
@@ -119,40 +83,23 @@ void ScsiCdrom::process_command()
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
xfer_len = READ_WORD_BE_U(&cmd[7]);
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
if (cmd[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str());
|
||||
}
|
||||
read(lba, xfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_LONG_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
read(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->read_toc();
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
this->bytes_out = read_toc(cmd, this->data_buf);
|
||||
if (this->status == ScsiStatus::GOOD) {
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
|
||||
this->illegal_command(cmd);
|
||||
}
|
||||
}
|
||||
@@ -184,8 +131,11 @@ bool ScsiCdrom::get_more_data() {
|
||||
return this->data_size != 0;
|
||||
}
|
||||
|
||||
void ScsiCdrom::read(const uint32_t lba, uint16_t nblocks, const uint8_t cmd_len)
|
||||
void ScsiCdrom::read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len)
|
||||
{
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
if (cmd_len == 6 && nblocks == 0)
|
||||
nblocks = 256;
|
||||
|
||||
@@ -203,9 +153,9 @@ int ScsiCdrom::test_unit_ready()
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
void ScsiCdrom::inquiry() {
|
||||
int page_num = cmd_buf[2];
|
||||
int alloc_len = cmd_buf[4];
|
||||
uint32_t ScsiCdrom::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
int page_num = cmd_ptr[2];
|
||||
int alloc_len = cmd_ptr[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
|
||||
@@ -215,42 +165,59 @@ void ScsiCdrom::inquiry() {
|
||||
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
this->data_buf[0] = 5; // device type: CD-ROM
|
||||
this->data_buf[1] = 0x80; // removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0x1F; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&this->data_buf[8], cdrom_vendor_sony_id, 8);
|
||||
std::memcpy(&this->data_buf[16], cdu8003a_product_id, 16);
|
||||
std::memcpy(&this->data_buf[32], cdu8003a_revision_id, 4);
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7", this->name.c_str(),
|
||||
alloc_len, this->last_selection_message);
|
||||
lun = this->last_selection_message & 7;
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
|
||||
alloc_len, cmd_ptr[1]);
|
||||
lun = cmd_ptr[1] >> 5;
|
||||
}
|
||||
|
||||
this->bytes_out = 36;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
data_ptr[0] = (lun == this->lun) ? 5 : 0x7f; // device type: CD-ROM
|
||||
data_ptr[1] = 0x80; // removable media
|
||||
data_ptr[2] = 2; // ANSI version: SCSI-2
|
||||
data_ptr[3] = 1; // response data format
|
||||
data_ptr[4] = 0x1F; // additional length
|
||||
data_ptr[5] = 0;
|
||||
data_ptr[6] = 0;
|
||||
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&data_ptr[8], vendor_info, 8);
|
||||
std::memcpy(&data_ptr[16], prod_info, 16);
|
||||
std::memcpy(&data_ptr[32], rev_info, 4);
|
||||
//std::memcpy(&data_ptr[36], serial_number, 8);
|
||||
//etc.
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
if (alloc_len < 36) {
|
||||
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
}
|
||||
else {
|
||||
memset(&data_ptr[36], 0, alloc_len - 36);
|
||||
}
|
||||
|
||||
return alloc_len;
|
||||
}
|
||||
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
|
||||
void ScsiCdrom::mode_sense()
|
||||
void ScsiCdrom::mode_sense_6()
|
||||
{
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
//uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
int num_blocks = this->size_blocks;
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0x80; // medium is write protected
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (num_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (num_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (num_blocks ) & 0xFFU;
|
||||
this->data_buf[ 5] = (this->size_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (this->size_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (this->size_blocks ) & 0xFFU;
|
||||
this->data_buf[ 8] = 0;
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = (this->block_size >> 8) & 0xFFU;
|
||||
@@ -278,7 +245,15 @@ void ScsiCdrom::mode_sense()
|
||||
this->data_buf[17] = 'p';
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
this->bytes_out = this->data_buf[0];
|
||||
@@ -287,79 +262,21 @@ void ScsiCdrom::mode_sense()
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_toc()
|
||||
void ScsiCdrom::mode_select_6(uint8_t param_len)
|
||||
{
|
||||
int tot_tracks;
|
||||
uint8_t start_track = this->cmd_buf[6];
|
||||
uint16_t alloc_len = (this->cmd_buf[7] << 8) + this->cmd_buf[8];
|
||||
bool is_msf = !!(this->cmd_buf[1] & 2);
|
||||
|
||||
if (this->cmd_buf[2] & 0xF) {
|
||||
ABORT_F("%s: unsupported format in READ_TOC", this->name.c_str());
|
||||
}
|
||||
|
||||
if (!alloc_len) {
|
||||
LOG_F(WARNING, "%s: zero allocation length passed to READ_TOC", this->name.c_str());
|
||||
if (!param_len)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!start_track) { // special case: track zero (lead-in) as starting track
|
||||
// return all tracks starting with track 1 plus lead-out
|
||||
start_track = 1;
|
||||
tot_tracks = this->num_tracks + 1;
|
||||
} else if (start_track == LEAD_OUT_TRK_NUM) {
|
||||
start_track = this->num_tracks + 1;
|
||||
tot_tracks = 1;
|
||||
} else if (start_track <= this->num_tracks) {
|
||||
tot_tracks = (this->num_tracks - start_track) + 2;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: invalid starting track %d in READ_TOC", this->name.c_str(),
|
||||
start_track);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
this->incoming_size = param_len;
|
||||
|
||||
uint8_t* buf_ptr = this->data_buf;
|
||||
std::memset(&this->data_buf[0], 0, 512);
|
||||
|
||||
int data_len = (tot_tracks * 8) + 2;
|
||||
this->post_xfer_action = [this]() {
|
||||
// TODO: parse the received mode parameter list here
|
||||
LOG_F(INFO, "Mode Select: received mode parameter list");
|
||||
};
|
||||
|
||||
// write TOC data header
|
||||
*buf_ptr++ = (data_len >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (data_len >> 0) & 0xFFU;
|
||||
*buf_ptr++ = 1; // 1st track number
|
||||
*buf_ptr++ = this->num_tracks; // last track number
|
||||
|
||||
for (int tx = 0; tx < tot_tracks; tx++) {
|
||||
if ((buf_ptr - this->data_buf + 8) > alloc_len)
|
||||
break; // exit the loop if the output buffer length is exhausted
|
||||
|
||||
TrackDescriptor& td = this->tracks[start_track + tx - 1];
|
||||
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = td.adr_ctrl;
|
||||
*buf_ptr++ = td.trk_num;
|
||||
*buf_ptr++ = 0; // reserved
|
||||
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(td.start_lba + 150);
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = msf.min;
|
||||
*buf_ptr++ = msf.sec;
|
||||
*buf_ptr++ = msf.frm;
|
||||
} else {
|
||||
*buf_ptr++ = (td.start_lba >> 24) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 16) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 0) & 0xFFU;
|
||||
}
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_capacity_10()
|
||||
@@ -374,20 +291,21 @@ void ScsiCdrom::read_capacity_10()
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 8;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
int last_lba = this->size_blocks - 1;
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
this->data_buf[0] = (last_lba >> 24) & 0xFFU;
|
||||
this->data_buf[1] = (last_lba >> 16) & 0xFFU;
|
||||
this->data_buf[2] = (last_lba >> 8) & 0xFFU;
|
||||
this->data_buf[3] = (last_lba >> 0) & 0xFFU;
|
||||
this->data_buf[4] = 0;
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = (this->block_size >> 8) & 0xFFU;
|
||||
this->data_buf[7] = this->block_size & 0xFFU;
|
||||
int last_lba = (int)this->size_blocks - 1;
|
||||
|
||||
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[4], this->block_size);
|
||||
|
||||
this->bytes_out = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
@@ -32,7 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class ScsiCdrom : public ScsiDevice, public CdromDrive {
|
||||
class ScsiCdrom : public CdromDrive, public ScsiDevice {
|
||||
public:
|
||||
ScsiCdrom(std::string name, int my_id);
|
||||
~ScsiCdrom() = default;
|
||||
@@ -44,15 +44,21 @@ public:
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
void read(uint32_t lba, uint16_t nblocks, uint8_t cmd_len);
|
||||
void inquiry();
|
||||
void mode_sense();
|
||||
void read_toc();
|
||||
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) override;
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6();
|
||||
void read_capacity_10();
|
||||
|
||||
private:
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
uint8_t data_buf[2048] = {};
|
||||
|
||||
//inquiry info
|
||||
char vendor_info[9] = "SONY ";
|
||||
char prod_info[17] = "CD-ROM CDU-8003A";
|
||||
char rev_info[5] = "1.9a";
|
||||
};
|
||||
|
||||
#endif // SCSI_CDROM_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,9 +26,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
void ScsiDevice::notify(ScsiMsg msg_type, int param)
|
||||
void ScsiDevice::notify(ScsiNotification notif_type, int param)
|
||||
{
|
||||
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
|
||||
if (notif_type == ScsiNotification::BUS_PHASE_CHANGE) {
|
||||
switch (param) {
|
||||
case ScsiPhase::RESET:
|
||||
LOG_F(9, "ScsiDevice %d: bus reset aknowledged", this->scsi_id);
|
||||
@@ -45,12 +45,11 @@ void ScsiDevice::notify(ScsiMsg msg_type, int param)
|
||||
return;
|
||||
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
|
||||
this->bus_obj->confirm_selection(this->scsi_id);
|
||||
this->seq_steps = nullptr;
|
||||
this->initiator_id = this->bus_obj->get_initiator_id();
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
|
||||
this->switch_phase(ScsiPhase::MESSAGE_OUT);
|
||||
this->last_selection_has_atention = true;
|
||||
this->last_selection_message = this->msg_buf[0];
|
||||
//LOG_F(SCSIDEVICE, "%s: received message:0x%02x", this->get_name().c_str(), this->msg_buf[0]);
|
||||
this->switch_phase(ScsiPhase::MESSAGE_OUT);
|
||||
} else {
|
||||
this->last_selection_has_atention = false;
|
||||
this->switch_phase(ScsiPhase::COMMAND);
|
||||
@@ -68,8 +67,36 @@ void ScsiDevice::switch_phase(const int new_phase)
|
||||
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
|
||||
}
|
||||
|
||||
bool ScsiDevice::allow_phase_change() {
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN | SCSI_CTRL_ACK) ==
|
||||
(SCSI_CTRL_ATN | SCSI_CTRL_ACK))
|
||||
ABORT_F("%s: reject message requested", this->name.c_str());
|
||||
|
||||
if (this->data_size || this->bus_obj->test_ctrl_lines(SCSI_CTRL_ACK))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiDevice::next_step()
|
||||
{
|
||||
// special case: data transfers during MESSAGE_IN phase
|
||||
// require handshaking. Rejecting needs to be detected too.
|
||||
if (bus_obj->current_phase() == ScsiPhase::MESSAGE_IN &&
|
||||
!this->allow_phase_change())
|
||||
return;
|
||||
|
||||
// check for puggable sequences and follow them if applicable
|
||||
if (this->seq_steps && *this->seq_steps >= 0) {
|
||||
if (this->cur_phase == *this->seq_steps) {
|
||||
this->seq_steps++;
|
||||
if (*this->seq_steps >= 0) {
|
||||
this->switch_phase(*this->seq_steps);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->data_size >= this->incoming_size) {
|
||||
@@ -95,6 +122,9 @@ void ScsiDevice::next_step()
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = 1;
|
||||
this->switch_phase(ScsiPhase::MESSAGE_IN);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
@@ -103,6 +133,7 @@ void ScsiDevice::next_step()
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
case ScsiPhase::BUS_FREE:
|
||||
this->bus_obj->release_ctrl_lines(this->scsi_id);
|
||||
this->seq_steps = nullptr;
|
||||
this->switch_phase(ScsiPhase::BUS_FREE);
|
||||
break;
|
||||
default:
|
||||
@@ -136,9 +167,6 @@ void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
|
||||
bytes_out = 0;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = 1;
|
||||
bytes_out = 1;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("ScsiDevice: unhandled phase %d in prepare_xfer()", this->cur_phase);
|
||||
@@ -153,14 +181,14 @@ int ScsiDevice::xfer_data() {
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
if (this->bus_obj->pull_data(this->initiator_id, this->msg_buf, 1)) {
|
||||
if (this->msg_buf[0] & 0x80) {
|
||||
if (this->msg_buf[0] & ScsiMessage::IDENTIFY) {
|
||||
LOG_F(9, "%s: IDENTIFY MESSAGE received, code = 0x%X",
|
||||
this->name.c_str(), this->msg_buf[0]);
|
||||
this->next_step();
|
||||
} else {
|
||||
ABORT_F("%s: unsupported message received, code = 0x%X",
|
||||
this->name.c_str(), this->msg_buf[0]);
|
||||
this->process_message();
|
||||
}
|
||||
if (this->last_selection_has_atention)
|
||||
this->last_selection_message = this->msg_buf[0];
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::COMMAND:
|
||||
@@ -221,13 +249,12 @@ int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
|
||||
return count;
|
||||
}
|
||||
|
||||
bool ScsiDevice::check_lun()
|
||||
{
|
||||
bool ScsiDevice::check_lun() {
|
||||
if (this->cmd_buf[1] >> 5 != this->lun) {
|
||||
LOG_F(ERROR, "%s: non-matching LUN", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x25; // Logical Unit Not Supported
|
||||
this->asc = ScsiError::INVALID_LUN;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
@@ -237,14 +264,48 @@ bool ScsiDevice::check_lun()
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd)
|
||||
{
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd) {
|
||||
LOG_F(ERROR, "%s: unsupported command: 0x%02x", this->name.c_str(), cmd[0]);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x20; // Invalid command operation code
|
||||
this->asc = ScsiError::INVALID_CMD;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
|
||||
void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = sense_key;
|
||||
this->asc = asc;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
|
||||
void ScsiDevice::process_message() {
|
||||
static int sdtr_response_seq[4] = {ScsiPhase::MESSAGE_OUT, ScsiPhase::MESSAGE_IN,
|
||||
ScsiPhase::COMMAND, -1};
|
||||
|
||||
if (this->msg_buf[0] == 1) { // extended messages
|
||||
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1) ||
|
||||
!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[2], this->msg_buf[1]))
|
||||
ABORT_F("%s: incomplete message received", this->name.c_str());
|
||||
|
||||
switch(this->msg_buf[2]) {
|
||||
case ScsiExtMessage::SYNCH_XFER_REQ:
|
||||
LOG_F(INFO, "%s: SDTR message received", this->name.c_str());
|
||||
// confirm synchronous transfer capability by sending back the SDTR message
|
||||
this->seq_steps = sdtr_response_seq;
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = 5;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported message %d", this->name.c_str(), this->msg_buf[2]);
|
||||
}
|
||||
} else if ((this->msg_buf[0] >> 4) == 2) { // two-byte messages
|
||||
if (!this->bus_obj->pull_data(this->initiator_id, &this->msg_buf[1], 1))
|
||||
ABORT_F("%s: incomplete message received", this->name.c_str());
|
||||
}
|
||||
}
|
||||
+247
-139
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
Copyright (C) 2018-25 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,6 +34,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
using namespace std;
|
||||
|
||||
ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) {
|
||||
this->data_buf_size = 1 << 22;
|
||||
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
|
||||
this->data_buf = this->data_buf_obj.get();
|
||||
}
|
||||
|
||||
void ScsiHardDisk::insert_image(std::string filename) {
|
||||
@@ -46,17 +49,12 @@ void ScsiHardDisk::insert_image(std::string filename) {
|
||||
uint64_t tb = (this->img_size + this->sector_size - 1) / this->sector_size;
|
||||
this->total_blocks = static_cast<int>(tb);
|
||||
if (this->total_blocks < 0 || tb != this->total_blocks) {
|
||||
ABORT_F("ScsiHardDisk: file size is too large");
|
||||
ABORT_F("%s: file size is too large", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiHardDisk::process_command() {
|
||||
uint32_t lba = 0;
|
||||
uint16_t transfer_len = 0;
|
||||
uint16_t alloc_len = 0;
|
||||
|
||||
uint8_t page_code = 0;
|
||||
uint8_t subpage_code = 0;
|
||||
uint32_t lba;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
@@ -69,98 +67,56 @@ void ScsiHardDisk::process_command() {
|
||||
|
||||
switch (cmd[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
alloc_len = cmd[4];
|
||||
req_sense(alloc_len);
|
||||
this->req_sense(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->format();
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
read(lba, transfer_len, 6);
|
||||
this->read(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
write(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->write(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
this->bytes_out = this->inquiry(cmd, this->data_buf);
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (cmd[4] & 1) == 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
read(lba, transfer_len, 10);
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
if (cmd[1] & 1) {
|
||||
ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str());
|
||||
}
|
||||
this->read(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
write(lba, transfer_len, 10);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
lba = READ_DWORD_BE_U(&cmd[2]);
|
||||
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
break;
|
||||
case ScsiCommand::READ_BUFFER:
|
||||
read_buffer();
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
default:
|
||||
this->illegal_command(cmd);
|
||||
}
|
||||
@@ -182,17 +138,20 @@ bool ScsiHardDisk::prepare_data() {
|
||||
} else {
|
||||
this->data_buf[0] = ScsiStatus::CHECK_CONDITION;
|
||||
}
|
||||
this->data_size = 1;
|
||||
this->bytes_out = 1;
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_buf[0] = this->msg_code;
|
||||
this->data_size = 1;
|
||||
this->bytes_out = 1;
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -202,42 +161,108 @@ int ScsiHardDisk::test_unit_ready() {
|
||||
}
|
||||
|
||||
int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
if (alloc_len != 252) {
|
||||
LOG_F(WARNING, "%s: inappropriate Allocation Length: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
//if (!check_lun())
|
||||
// return;
|
||||
|
||||
//int next_phase;
|
||||
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
lun = this->last_selection_message & 7;
|
||||
}
|
||||
return ScsiError::NO_ERROR; // placeholder - no sense
|
||||
else {
|
||||
lun = cmd_buf[1] >> 5;
|
||||
}
|
||||
|
||||
if (lun == this->lun) {
|
||||
this->status = ScsiStatus::GOOD;
|
||||
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
|
||||
this->data_buf[12] = this->asc; // addition sense code
|
||||
this->data_buf[13] = this->ascq; // additional sense qualifier
|
||||
this->data_buf[15] = this->sksv; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
|
||||
this->data_buf[16] = this->field >> 8; // field pointer
|
||||
this->data_buf[17] = this->field;
|
||||
}
|
||||
else {
|
||||
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
|
||||
this->data_buf[12] = ScsiError::INVALID_LUN; // addition sense code = Logical Unit Not Supported
|
||||
this->data_buf[13] = 0; // additional sense qualifier
|
||||
this->data_buf[15] = 0; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
|
||||
this->data_buf[16] = 0; // field pointer
|
||||
this->data_buf[17] = 0;
|
||||
}
|
||||
|
||||
{
|
||||
// FIXME: there should be a way to set the VALID and ILI bits.
|
||||
this->data_buf[ 0] = 0x70; // Valid:0x80, Error Code:0x7f
|
||||
this->data_buf[ 1] = 0; // segment number
|
||||
this->data_buf[ 3] = 0; // information
|
||||
this->data_buf[ 4] = 0;
|
||||
this->data_buf[ 5] = 0;
|
||||
this->data_buf[ 6] = 0;
|
||||
this->data_buf[ 7] = 10; // additional sense length
|
||||
this->data_buf[ 8] = 0; // command specific information
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = 0;
|
||||
this->data_buf[11] = 0;
|
||||
this->data_buf[14] = 0; // field replaceable unit code
|
||||
this->data_buf[18] = 0; // reserved
|
||||
this->data_buf[19] = 0; // reserved
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len; // Open Firmware 1.0.5 asks for 18 bytes.
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
void ScsiHardDisk::inquiry() {
|
||||
int page_num = cmd_buf[2];
|
||||
int alloc_len = cmd_buf[4];
|
||||
uint32_t ScsiHardDisk::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
int page_num = cmd_ptr[2];
|
||||
int alloc_len = cmd_ptr[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
if (alloc_len >= 36) {
|
||||
this->data_buf[0] = 0; // device type: Direct-access block device
|
||||
this->data_buf[1] = 0; // non-removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(data_buf + 8, vendor_info, 8);
|
||||
std::memcpy(data_buf + 16, prod_info, 16);
|
||||
std::memcpy(data_buf + 32, rev_info, 4);
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str());
|
||||
}
|
||||
|
||||
this->bytes_out = 36;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with ATN LUN = %02x & 7",
|
||||
this->name.c_str(), alloc_len, this->last_selection_message);
|
||||
lun = this->last_selection_message & 7;
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: allocation length too small: %d", this->name.c_str(),
|
||||
LOG_F(INFO, "%s: INQUIRY (%d bytes) with NO ATN LUN = %02x >> 5", this->name.c_str(),
|
||||
alloc_len, cmd_ptr[1]);
|
||||
lun = cmd_ptr[1] >> 5;
|
||||
}
|
||||
|
||||
data_ptr[0] = (lun == this->lun) ? 0 : 0x7f; // device type: Direct-access block device (hard drive)
|
||||
data_ptr[1] = 0; // non-removable media; 0x80 = removable media
|
||||
data_ptr[2] = 2; // ANSI version: SCSI-2
|
||||
data_ptr[3] = 1; // response data format
|
||||
data_ptr[4] = 0x1F; // additional length
|
||||
data_ptr[5] = 0;
|
||||
data_ptr[6] = 0;
|
||||
data_ptr[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&data_ptr[8], vendor_info, 8);
|
||||
std::memcpy(&data_ptr[16], prod_info, 16);
|
||||
std::memcpy(&data_ptr[32], rev_info, 4);
|
||||
//std::memcpy(&data_ptr[36], serial_number, 8);
|
||||
//etc.
|
||||
|
||||
if (alloc_len < 36) {
|
||||
LOG_F(ERROR, "%s: allocation length too small: %d", this->name.c_str(),
|
||||
alloc_len);
|
||||
}
|
||||
else {
|
||||
memset(&data_ptr[36], 0, alloc_len - 36);
|
||||
}
|
||||
|
||||
return alloc_len;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::send_diagnostic() {
|
||||
@@ -266,51 +291,112 @@ static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
void ScsiHardDisk::mode_sense_6() {
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
uint8_t page_ctrl = this->cmd_buf[2] >> 6;
|
||||
uint8_t sub_page_code = this->cmd_buf[3];
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0; // medium is write enabled
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
if (page_ctrl == 1) {
|
||||
LOG_F(INFO, "%s: page_ctrl 1 CHANGEABLE VALUES is not implemented", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (this->total_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (this->total_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (this->total_blocks ) & 0xFFU;
|
||||
if (page_ctrl == 3) {
|
||||
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = SAVING_NOT_SUPPORTED;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0; // 0:medium is not write protected; 0x80 write protected
|
||||
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
WRITE_DWORD_BE_A(&this->data_buf[4], this->total_blocks);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[8], this->sector_size);
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
uint8_t *p_buf = &this->data_buf[12];
|
||||
bool got_page = false;
|
||||
int page_size;
|
||||
|
||||
switch(page_code) {
|
||||
case 1: // read-write error recovery page
|
||||
this->data_buf[13] = 6; // data size - 1
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
break;
|
||||
case 3: // Format device page
|
||||
this->data_buf[13] = 22; // data size - 1
|
||||
std::memset(&this->data_buf[14], 0, 22);
|
||||
if (page_code == 1 || page_code == 0x3f) { // read-write error recovery page
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
page_size = 8;
|
||||
p_buf[0] = 1; // page code
|
||||
p_buf[1] = page_size - 2; // data size - 1
|
||||
std::memset(&p_buf[2], 0, 6);
|
||||
p_buf += page_size;
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (page_code == 3 || page_code == 0x3f) { // Format device page
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
page_size = 24;
|
||||
p_buf[ 0] = 3; // page code
|
||||
p_buf[ 1] = page_size - 2; // data size - 1
|
||||
std::memset(&p_buf[2], 0, 22);
|
||||
// default values taken from Empire 540/1080S manual
|
||||
this->data_buf[15] = 6; // tracks per defect zone
|
||||
this->data_buf[17] = 1; // alternate sectors per zone
|
||||
this->data_buf[23] = 92; // sectors per track in the outermost zone
|
||||
this->data_buf[27] = 1; // interleave factor
|
||||
this->data_buf[29] = 19; // track skew factor
|
||||
this->data_buf[31] = 25; // cylinder skew factor
|
||||
this->data_buf[32] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
WRITE_WORD_BE_U(&this->data_buf[24], 512); // bytes per sector
|
||||
break;
|
||||
case 0x30: // Copyright page for Apple certified drives
|
||||
this->data_buf[13] = 22; // data size - 1
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
};
|
||||
WRITE_WORD_BE_U(&p_buf[ 2], 6); // tracks per defect zone
|
||||
WRITE_WORD_BE_U(&p_buf[ 4], 1); // alternate sectors per zone
|
||||
WRITE_WORD_BE_U(&p_buf[10], 92); // sectors per track in the outermost zone
|
||||
WRITE_WORD_BE_U(&p_buf[12], 512); // bytes per sector
|
||||
WRITE_WORD_BE_U(&p_buf[14], 1); // interleave factor
|
||||
WRITE_WORD_BE_U(&p_buf[16], 19); // track skew factor
|
||||
WRITE_WORD_BE_U(&p_buf[18], 25); // cylinder skew factor
|
||||
p_buf[20] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
p_buf += page_size;
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (page_code == 0x30 || page_code == 0x3f) { // Copyright page for Apple certified drives
|
||||
if (sub_page_code != 0x00 && sub_page_code != 0xff)
|
||||
goto bad_sub_page;
|
||||
page_size = 24;
|
||||
p_buf[0] = 0x30; // page code
|
||||
p_buf[1] = page_size - 2; // data size - 1
|
||||
std::memcpy(&p_buf[2], Apple_Copyright_Page_Data, 22);
|
||||
p_buf += page_size;
|
||||
got_page = true;
|
||||
}
|
||||
|
||||
if (!(got_page || page_code == 0x3f)) { // not any of the supported pages or all pages
|
||||
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
bad_sub_page:
|
||||
LOG_F(WARNING, "%s: unsupported page/subpage %02xh/%02xh in MODE_SENSE_6", this->name.c_str(), page_code, sub_page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 3;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
// adjust for overall mode sense data length
|
||||
this->data_buf[0] += this->data_buf[13] + 1;
|
||||
this->data_buf[0] = p_buf - this->data_buf - 1;
|
||||
|
||||
this->bytes_out = std::min(alloc_len, (uint8_t)this->data_buf[0]);
|
||||
this->bytes_out = std::min((int)alloc_len, (int)this->data_buf[0] + 1);
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
@@ -326,22 +412,28 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 8;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
uint32_t last_lba = this->total_blocks - 1;
|
||||
uint32_t blk_len = this->sector_size;
|
||||
|
||||
WRITE_DWORD_BE_A(&data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&data_buf[4], blk_len);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&this->data_buf[4], blk_len);
|
||||
|
||||
this->bytes_out = 8;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
|
||||
void ScsiHardDisk::format() {
|
||||
LOG_F(WARNING, "%s: attempt to format the disk!", this->name.c_str());
|
||||
|
||||
@@ -354,18 +446,26 @@ void ScsiHardDisk::format() {
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
if (!check_lun())
|
||||
return;
|
||||
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(data_buf, 0, sizeof(data_buf));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= this->sector_size;
|
||||
|
||||
if (transfer_size > this->data_buf_size) {
|
||||
while (transfer_size > this->data_buf_size)
|
||||
this->data_buf_size <<= 1;
|
||||
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
|
||||
this->data_buf = this->data_buf_obj.get();
|
||||
}
|
||||
std::memset(this->data_buf, 0, transfer_size);
|
||||
|
||||
uint64_t device_offset = (uint64_t)lba * this->sector_size;
|
||||
|
||||
this->disk_img.read(data_buf, device_offset, transfer_size);
|
||||
this->disk_img.read(this->data_buf, device_offset, transfer_size);
|
||||
|
||||
this->bytes_out = transfer_size;
|
||||
|
||||
@@ -374,12 +474,18 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
|
||||
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= this->sector_size;
|
||||
|
||||
if (transfer_size > this->data_buf_size) {
|
||||
while (transfer_size > this->data_buf_size)
|
||||
this->data_buf_size <<= 1;
|
||||
this->data_buf_obj = std::unique_ptr<uint8_t[]>(new uint8_t[this->data_buf_size]);
|
||||
this->data_buf = this->data_buf_obj.get();
|
||||
}
|
||||
|
||||
uint64_t device_offset = (uint64_t)lba * this->sector_size;
|
||||
|
||||
this->incoming_size = transfer_size;
|
||||
@@ -387,6 +493,8 @@ void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
this->post_xfer_action = [this, device_offset]() {
|
||||
this->disk_img.write(this->data_buf, device_offset, this->incoming_size);
|
||||
};
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read_buffer() {
|
||||
|
||||
@@ -49,7 +49,7 @@ protected:
|
||||
|
||||
void mode_sense_6();
|
||||
void format();
|
||||
void inquiry();
|
||||
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
|
||||
void read_capacity_10();
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
@@ -63,15 +63,18 @@ private:
|
||||
int total_blocks;
|
||||
uint64_t file_offset = 0;
|
||||
static const int sector_size = 512;
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
|
||||
uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!
|
||||
std::unique_ptr<uint8_t[]> data_buf_obj = nullptr;
|
||||
uint8_t* data_buf = nullptr;
|
||||
uint32_t data_buf_size = 0;
|
||||
|
||||
uint8_t error = ScsiError::NO_ERROR;
|
||||
uint8_t msg_code = 0;
|
||||
|
||||
//inquiry info
|
||||
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
|
||||
char vendor_info[8] = {'Q', 'U', 'A', 'N', 'T', 'U', 'M', '\0'};
|
||||
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
|
||||
char rev_info[4] = {'d', 'i', '0', '1'};
|
||||
};
|
||||
|
||||
+233
-134
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,30 +47,25 @@ ViaCuda::ViaCuda() {
|
||||
// VIA reset clears all internal registers to logic 0
|
||||
// except timers/counters and the shift register
|
||||
// as stated in the 6522 datasheet
|
||||
this->via_regs[VIA_A] = 0;
|
||||
this->via_regs[VIA_B] = 0;
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
this->via_porta = 0;
|
||||
this->via_portb = 0;
|
||||
this->via_ddrb = 0;
|
||||
this->via_ddra = 0;
|
||||
this->via_acr = 0;
|
||||
this->via_pcr = 0;
|
||||
|
||||
// load maximum value into the timer registers for safety
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_T2CL] = 0xFF;
|
||||
this->via_regs[VIA_T2CH] = 0xFF;
|
||||
this->via_t1ll = 0xFF;
|
||||
this->via_t1lh = 0xFF;
|
||||
this->via_t2cl = 0xFF;
|
||||
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
|
||||
// intialize counters/timers
|
||||
this->t1_counter = 0xFFFF;
|
||||
this->t1_active = false;
|
||||
this->t2_counter = 0xFFFF;
|
||||
this->t2_active = false;
|
||||
|
||||
// calculate VIA clock duration in ns
|
||||
this->via_clk_dur = 1.0f / VIA_CLOCK_HZ * NS_PER_SEC;
|
||||
@@ -87,21 +82,32 @@ ViaCuda::ViaCuda() {
|
||||
this->cuda_init();
|
||||
|
||||
this->int_ctrl = nullptr;
|
||||
|
||||
std::tm tm = {
|
||||
.tm_sec = 0,
|
||||
.tm_min = 0,
|
||||
.tm_hour = 0,
|
||||
.tm_mday = 1,
|
||||
.tm_mon = 1 - 1,
|
||||
.tm_year = 1904 - 1900,
|
||||
.tm_isdst = 1 // -1 = Use DST value from local time zone; 0 = not summer; 1 = is summer time
|
||||
};
|
||||
mac_epoch = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
if (this->sr_timer_on) {
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_on = false;
|
||||
this->sr_timer_id = 0;
|
||||
}
|
||||
if (this->t1_active) {
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_active = false;
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
if (this->t2_active) {
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_active = false;
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
if (this->treq_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->treq_timer_id);
|
||||
@@ -128,24 +134,29 @@ void ViaCuda::cuda_init() {
|
||||
}
|
||||
|
||||
uint8_t ViaCuda::read(int reg) {
|
||||
/* reading from some VIA registers triggers special actions */
|
||||
uint8_t value;
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
return (this->via_regs[VIA_B]);
|
||||
return this->via_portb; //(this->via_portb & ~this->via_ddrb) | this->last_orb;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
case VIA_IFR:
|
||||
return this->_via_ifr;
|
||||
return this->via_porta;
|
||||
case VIA_DIRB:
|
||||
return this->via_ddrb;
|
||||
case VIA_DIRA:
|
||||
return this->via_ddra;
|
||||
case VIA_T1CL:
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
|
||||
case VIA_T1CH:
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
|
||||
case VIA_T1LL:
|
||||
return this->via_t1ll;
|
||||
case VIA_T1LH:
|
||||
return this->via_t1lh;
|
||||
case VIA_T2CL:
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
@@ -153,37 +164,122 @@ uint8_t ViaCuda::read(int reg) {
|
||||
case VIA_T2CH:
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
|
||||
case VIA_SR:
|
||||
value = this->via_sr;
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
return value;
|
||||
case VIA_ACR:
|
||||
return this->via_acr;
|
||||
case VIA_PCR:
|
||||
return this->via_pcr;
|
||||
case VIA_IFR:
|
||||
return this->_via_ifr;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
}
|
||||
|
||||
return (this->via_regs[reg & 0xF]);
|
||||
return 0; // should never happen!
|
||||
}
|
||||
|
||||
void ViaCuda::write(int reg, uint8_t value) {
|
||||
this->via_regs[reg & 0xF] = value;
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
write(value);
|
||||
this->last_orb = value & this->via_ddrb;
|
||||
this->via_portb = (this->via_portb & ~this->via_ddrb) | this->last_orb;
|
||||
// ensure the proper VIA configuration before calling Cuda
|
||||
if ((this->via_ddrb & 0x38) == 0x30)
|
||||
this->write(this->via_portb);
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
this->via_porta = value;
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A!");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
this->via_ddrb = value;
|
||||
LOG_F(9, "VIA_DIRB = 0x%X", value);
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
this->via_ddra = value;
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
case VIA_T1CL:
|
||||
this->via_t1cl = value;
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_acr & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_t1cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_T1LL:
|
||||
this->via_t1ll = value;
|
||||
break;
|
||||
case VIA_T1LH:
|
||||
this->via_t1lh = value;
|
||||
break;
|
||||
case VIA_T2CL:
|
||||
this->via_t2cl = value;
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_acr & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_t2cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t2_timer_id = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->via_sr = value;
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_ACR:
|
||||
this->via_acr = value;
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
this->via_pcr = value;
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
break;
|
||||
case VIA_IFR:
|
||||
// for each "1" in value clear the corresponding flags
|
||||
this->_via_ifr &= ~value;
|
||||
@@ -198,70 +294,14 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
update_irq();
|
||||
print_enabled_ints();
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_regs[VIA_ACR] & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_regs[VIA_ACR]);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_active = false;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_regs[VIA_T1CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
this->t1_active = true;
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_regs[VIA_ACR] & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_active) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_active = false;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_regs[VIA_T2CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
this->t2_active = true;
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last_time)
|
||||
{
|
||||
// calcualte current counter value based on elapsed time and timer frequency
|
||||
// calculate current counter value based on elapsed time and timer frequency
|
||||
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
|
||||
uint32_t diff = (cur_time - last_time) / this->via_clk_dur;
|
||||
uint32_t diff = uint32_t((cur_time - last_time) / this->via_clk_dur);
|
||||
return last_val - diff;
|
||||
}
|
||||
|
||||
@@ -287,20 +327,17 @@ void ViaCuda::update_irq()
|
||||
}
|
||||
|
||||
void ViaCuda::assert_sr_int() {
|
||||
this->sr_timer_on = false;
|
||||
this->_via_ifr |= VIA_IF_SR;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t1_int() {
|
||||
this->_via_ifr |= VIA_IF_T1;
|
||||
this->t1_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void ViaCuda::assert_t2_int() {
|
||||
this->_via_ifr |= VIA_IF_T2;
|
||||
this->t2_active = false;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
@@ -333,21 +370,24 @@ void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
}
|
||||
|
||||
void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
|
||||
if (this->sr_timer_on) {
|
||||
if (this->sr_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
|
||||
this->sr_timer_on = false;
|
||||
this->sr_timer_id = 0;
|
||||
}
|
||||
this->sr_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
timeout_ns,
|
||||
[this]() { this->assert_sr_int(); });
|
||||
this->sr_timer_on = true;
|
||||
[this]() {
|
||||
this->sr_timer_id = 0;
|
||||
this->assert_sr_int();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ViaCuda::write(uint8_t new_state) {
|
||||
int new_tip = !!(new_state & CUDA_TIP);
|
||||
int new_byteack = !!(new_state & CUDA_BYTEACK);
|
||||
|
||||
/* return if there is no state change */
|
||||
// return if there is no state change
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
@@ -356,7 +396,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
if (new_tip) {
|
||||
if (new_byteack) {
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
|
||||
if (this->in_count) {
|
||||
@@ -366,7 +406,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer_id = 0;
|
||||
});
|
||||
@@ -375,7 +415,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
@@ -384,9 +424,9 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
// send dummy byte as idle acknowledge or attention
|
||||
schedule_sr_int(USECS_TO_NSECS(61));
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->via_acr & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->in_count < sizeof(this->in_buf)) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
this->in_buf[this->in_count++] = this->via_sr;
|
||||
// tell the system we've read the byte after 71 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(71));
|
||||
} else {
|
||||
@@ -402,22 +442,22 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
/* sends zeros to host ad infinitum */
|
||||
void ViaCuda::null_out_handler() {
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
this->via_sr = 0;
|
||||
}
|
||||
|
||||
/* sends PRAM content to host ad infinitum */
|
||||
void ViaCuda::pram_out_handler()
|
||||
{
|
||||
this->via_regs[VIA_SR] = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
this->via_sr = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
}
|
||||
|
||||
/* sends data from out_buf until exhausted, then switches to next_out_handler */
|
||||
void ViaCuda::out_buf_handler() {
|
||||
if (this->out_pos < this->out_count) {
|
||||
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
|
||||
this->via_sr = this->out_buf[this->out_pos++];
|
||||
if (!this->is_open_ended && this->out_pos >= this->out_count) {
|
||||
// tell the host this will be the last byte
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
} else if (this->is_open_ended) {
|
||||
@@ -426,7 +466,7 @@ void ViaCuda::out_buf_handler() {
|
||||
(this->*out_handler)();
|
||||
} else {
|
||||
this->out_count = 0;
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
}
|
||||
@@ -473,7 +513,7 @@ void ViaCuda::process_packet() {
|
||||
for (int i = 0; i < this->in_count; i++) {
|
||||
LOG_F(9, "0x%X ,", this->in_buf[i]);
|
||||
}
|
||||
pseudo_command(this->in_buf[1], this->in_count - 2);
|
||||
pseudo_command();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported packet type = %d", this->in_buf[0]);
|
||||
@@ -495,10 +535,7 @@ void ViaCuda::process_adb_command() {
|
||||
}
|
||||
|
||||
void ViaCuda::autopoll_handler() {
|
||||
if (!this->autopoll_enabled)
|
||||
return;
|
||||
|
||||
uint8_t poll_command = this->adb_bus_obj->poll();
|
||||
uint8_t poll_command = this->autopoll_enabled ? this->adb_bus_obj->poll() : 0;
|
||||
|
||||
if (poll_command) {
|
||||
if (!this->old_tip || !this->treq) {
|
||||
@@ -515,17 +552,48 @@ void ViaCuda::autopoll_handler() {
|
||||
}
|
||||
|
||||
// assert TREQ
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ;
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
schedule_sr_int(USECS_TO_NSECS(30));
|
||||
} else if (this->one_sec_mode != 0) {
|
||||
uint32_t this_time = calc_real_time();
|
||||
if (this_time != this->last_time) {
|
||||
/*
|
||||
We'll send a time packet every 4
|
||||
seconds just in case we get out of
|
||||
sync.
|
||||
*/
|
||||
bool send_time = !(this->last_time & 3);
|
||||
if (send_time || this->one_sec_mode < 3) {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = CUDA_GET_REAL_TIME;
|
||||
if (send_time || this->one_sec_mode == 1) {
|
||||
uint32_t real_time = this_time + this->time_offset;
|
||||
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
|
||||
this->out_count = 7;
|
||||
}
|
||||
} else if (this->one_sec_mode == 3) {
|
||||
response_header(CUDA_PKT_TICK, 0);
|
||||
this->out_count = 1;
|
||||
}
|
||||
this->last_time = this_time;
|
||||
|
||||
// assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
schedule_sr_int(USECS_TO_NSECS(30));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
void ViaCuda::pseudo_command() {
|
||||
uint16_t addr;
|
||||
int i;
|
||||
int cmd = this->in_buf[1];
|
||||
|
||||
switch (cmd) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
@@ -556,13 +624,14 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
}
|
||||
this->is_open_ended = true;
|
||||
break;
|
||||
case CUDA_GET_REAL_TIME:
|
||||
case CUDA_GET_REAL_TIME: {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->out_buf[2] = (uint8_t)((this->real_time >> 24) & 0xFF);
|
||||
this->out_buf[3] = (uint8_t)((this->real_time >> 16) & 0xFF);
|
||||
this->out_buf[4] = (uint8_t)((this->real_time >> 8) & 0xFF);
|
||||
this->out_buf[5] = (uint8_t)((this->real_time) & 0xFF);
|
||||
uint32_t this_time = this->calc_real_time();
|
||||
uint32_t real_time = this_time + this->time_offset;
|
||||
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
|
||||
this->out_count = 7;
|
||||
break;
|
||||
}
|
||||
case CUDA_WRITE_MCU_MEM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
// if addr is inside PRAM, update PRAM with data from in_buf
|
||||
@@ -587,13 +656,13 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
error_response(CUDA_ERR_BAD_PAR);
|
||||
}
|
||||
break;
|
||||
case CUDA_SET_REAL_TIME:
|
||||
case CUDA_SET_REAL_TIME: {
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
this->real_time = ((uint32_t)in_buf[2]) >> 24;
|
||||
this->real_time += ((uint32_t)in_buf[3]) >> 16;
|
||||
this->real_time += ((uint32_t)in_buf[4]) >> 8;
|
||||
this->real_time += ((uint32_t)in_buf[5]);
|
||||
uint32_t real_time = this->calc_real_time();
|
||||
uint32_t new_time = READ_DWORD_BE_U(&in_buf[2]);
|
||||
this->time_offset = new_time - real_time;
|
||||
break;
|
||||
}
|
||||
case CUDA_WRITE_PRAM:
|
||||
addr = READ_WORD_BE_A(&this->in_buf[2]);
|
||||
if (addr <= 0xFF) {
|
||||
@@ -637,7 +706,11 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
this->out_buf[3] = (uint8_t)((this->device_mask) & 0xFF);
|
||||
break;
|
||||
case CUDA_ONE_SECOND_MODE:
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt - Byte Sent: %d", this->in_buf[2]);
|
||||
LOG_F(INFO, "Cuda: One Second Interrupt Mode: %d", this->in_buf[2]);
|
||||
this->one_sec_mode = this->in_buf[2];
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_SET_POWER_MESSAGES:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
@@ -660,8 +733,12 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
power_on = false;
|
||||
power_off_reason = po_restart;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_POWER_DOWN:
|
||||
LOG_F(INFO, "Cuda: system shutdown");
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x!", cmd);
|
||||
@@ -673,9 +750,31 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ViaCuda::calc_real_time() {
|
||||
std::chrono::time_point<std::chrono::system_clock> end;
|
||||
if (is_deterministic) {
|
||||
// March 24, 2001 was the public release date of Mac OS X.
|
||||
std::tm tm = {
|
||||
.tm_sec = 0,
|
||||
.tm_min = 0,
|
||||
.tm_hour = 12,
|
||||
.tm_mday = 24,
|
||||
.tm_mon = 3 - 1,
|
||||
.tm_year = 2001 - 1900,
|
||||
.tm_isdst = 0
|
||||
};
|
||||
end = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
} else {
|
||||
end = std::chrono::system_clock::now();
|
||||
}
|
||||
auto elapsed_systemclock = end - this->mac_epoch;
|
||||
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(elapsed_systemclock);
|
||||
return uint32_t(elapsed_seconds.count());
|
||||
}
|
||||
|
||||
/* sends data from the current I2C to host ad infinitum */
|
||||
void ViaCuda::i2c_handler() {
|
||||
this->receive_byte(this->curr_i2c_addr, &this->via_regs[VIA_SR]);
|
||||
this->receive_byte(this->curr_i2c_addr, &this->via_sr);
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes) {
|
||||
@@ -752,7 +851,7 @@ void ViaCuda::i2c_comb_transaction(
|
||||
}
|
||||
|
||||
static const vector<string> Cuda_Subdevices = {
|
||||
"AdbBus", "AdbMouse", "AdbKeyboard"
|
||||
"AdbBus"
|
||||
};
|
||||
|
||||
static const DeviceDescription ViaCuda_Descriptor = {
|
||||
|
||||
+80
-64
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -48,30 +48,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
class AdbBus;
|
||||
class InterruptCtrl;
|
||||
|
||||
#define VIA_CLOCK_HZ 783360
|
||||
constexpr auto VIA_CLOCK_HZ = 783360;
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
VIA_B = 0x00, /* input/output register B */
|
||||
VIA_A = 0x01, /* input/output register A */
|
||||
VIA_DIRB = 0x02, /* direction B */
|
||||
VIA_DIRA = 0x03, /* direction A */
|
||||
VIA_T1CL = 0x04, /* low-order timer 1 counter */
|
||||
VIA_T1CH = 0x05, /* high-order timer 1 counter */
|
||||
VIA_T1LL = 0x06, /* low-order timer 1 latches */
|
||||
VIA_T1LH = 0x07, /* high-order timer 1 latches */
|
||||
VIA_T2CL = 0x08, /* low-order timer 2 latches */
|
||||
VIA_T2CH = 0x09, /* high-order timer 2 counter */
|
||||
VIA_SR = 0x0A, /* shift register */
|
||||
VIA_ACR = 0x0B, /* auxiliary control register */
|
||||
VIA_PCR = 0x0C, /* periheral control register */
|
||||
VIA_IFR = 0x0D, /* interrupt flag register */
|
||||
VIA_IER = 0x0E, /* interrupt enable register */
|
||||
VIA_ANH = 0x0F, /* input/output register A, no handshake */
|
||||
VIA_B = 0x00, // input/output register B
|
||||
VIA_A = 0x01, // input/output register A
|
||||
VIA_DIRB = 0x02, // direction B
|
||||
VIA_DIRA = 0x03, // direction A
|
||||
VIA_T1CL = 0x04, // low-order timer 1 counter
|
||||
VIA_T1CH = 0x05, // high-order timer 1 counter
|
||||
VIA_T1LL = 0x06, // low-order timer 1 latches
|
||||
VIA_T1LH = 0x07, // high-order timer 1 latches
|
||||
VIA_T2CL = 0x08, // low-order timer 2 latches
|
||||
VIA_T2CH = 0x09, // high-order timer 2 counter
|
||||
VIA_SR = 0x0A, // shift register
|
||||
VIA_ACR = 0x0B, // auxiliary control register
|
||||
VIA_PCR = 0x0C, // periheral control register
|
||||
VIA_IFR = 0x0D, // interrupt flag register
|
||||
VIA_IER = 0x0E, // interrupt enable register
|
||||
VIA_ANH = 0x0F, // input/output register A, no handshake
|
||||
};
|
||||
|
||||
/** VIA interrupt flags */
|
||||
@@ -92,11 +93,11 @@ enum class ViaLine {
|
||||
CB2
|
||||
};
|
||||
|
||||
/** Cuda communication signals. */
|
||||
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
|
||||
CUDA_BYTEACK = 0x10, /* byte acknowledge: 0 - true, 1 - false */
|
||||
CUDA_TREQ = 0x08 /* Cuda requests transaction from host */
|
||||
CUDA_TIP = 0x20, // transaction in progress
|
||||
CUDA_BYTEACK = 0x10, // byte acknowledge/handshake
|
||||
CUDA_TREQ = 0x08 // Cuda requests transaction from host
|
||||
};
|
||||
|
||||
/** Cuda packet types. */
|
||||
@@ -110,47 +111,50 @@ enum {
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
|
||||
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
CUDA_WARM_START = 0x00, // warm start
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, // start/stop device auto-polling
|
||||
CUDA_READ_MCU_MEM = 0x02, // read internal Cuda memory
|
||||
CUDA_GET_REAL_TIME = 0x03, // get real time
|
||||
CUDA_READ_PRAM = 0x07, // read parameter RAM
|
||||
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
|
||||
CUDA_SET_REAL_TIME = 0x09, // set real time
|
||||
CUDA_POWER_DOWN = 0x0A, // power down system
|
||||
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
|
||||
CUDA_RESTART_SYSTEM = 0x11, // restart system
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
|
||||
CUDA_SET_DEVICE_LIST = 0x19, // set device list
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
|
||||
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
|
||||
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
|
||||
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
|
||||
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
|
||||
};
|
||||
|
||||
/** Cuda error codes. */
|
||||
enum {
|
||||
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
|
||||
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
|
||||
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
|
||||
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
|
||||
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
|
||||
CUDA_ERR_BAD_PKT = 1, // invalid packet type
|
||||
CUDA_ERR_BAD_CMD = 2, // invalid pseudo command
|
||||
CUDA_ERR_BAD_SIZE = 3, // invalid packet size
|
||||
CUDA_ERR_BAD_PAR = 4, // invalid parameter
|
||||
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
|
||||
};
|
||||
|
||||
#define CUDA_IN_BUF_SIZE 256
|
||||
constexpr auto CUDA_IN_BUF_SIZE = 256;
|
||||
|
||||
/** PRAM addresses within Cuda's internal memory */
|
||||
#define CUDA_PRAM_START 0x100 // starting address of PRAM
|
||||
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
|
||||
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
|
||||
/** PRAM addresses within Cuda's internal memory. */
|
||||
// = 0xA1; // byte, read/write 0x00 (Power Mac 6100)
|
||||
// = 0xB3; // 2 bytes, write 0x3020 (Power Mac 6100)
|
||||
constexpr auto CUDA_PRAM_START = 0x100; // starting address of PRAM
|
||||
constexpr auto CUDA_PRAM_END = 0x1FF; // last byte of PRAM
|
||||
constexpr auto CUDA_ROM_START = 0xF00; // starting address of ROM containing Cuda FW
|
||||
|
||||
/** Latest Cuda Firmware version. */
|
||||
#define CUDA_FW_VERSION_MAJOR 0x0002
|
||||
#define CUDA_FW_VERSION_MINOR 0x0029
|
||||
constexpr auto CUDA_FW_VERSION_MAJOR = 0x0002;
|
||||
constexpr auto CUDA_FW_VERSION_MINOR = 0x0029;
|
||||
|
||||
class ViaCuda : public HWComponent, public I2CBus {
|
||||
public:
|
||||
@@ -175,29 +179,37 @@ public:
|
||||
|
||||
private:
|
||||
// VIA virtual HW registers
|
||||
uint8_t via_regs[16];
|
||||
uint8_t via_portb = 0;
|
||||
uint8_t via_porta = 0;
|
||||
uint8_t via_ddrb = 0;
|
||||
uint8_t via_ddra = 0;
|
||||
uint8_t via_t1cl = 0xFF;
|
||||
uint8_t via_t1ll = 0xFF;
|
||||
uint8_t via_t1lh = 0xFF;
|
||||
uint8_t via_t2cl = 0xFF;
|
||||
uint8_t via_sr;
|
||||
uint8_t via_acr = 0;
|
||||
uint8_t via_pcr = 0;
|
||||
|
||||
float via_clk_dur; // one VIA clock duration = 1,27655 us
|
||||
|
||||
// VIA internal state
|
||||
uint32_t sr_timer_id = 0;
|
||||
bool sr_timer_on = false;
|
||||
uint8_t last_orb = 0; // last value written to the ORB register.
|
||||
|
||||
// timer 1 state
|
||||
bool t1_active;
|
||||
uint16_t t1_counter;
|
||||
uint32_t t1_timer_id = 0;
|
||||
uint64_t t1_start_time = 0;
|
||||
|
||||
// timer 2 state
|
||||
bool t2_active;
|
||||
uint16_t t2_counter;
|
||||
uint32_t t2_timer_id = 0;
|
||||
uint64_t t2_start_time = 0;
|
||||
|
||||
// VIA interrupt related stuff
|
||||
InterruptCtrl* int_ctrl;
|
||||
uint32_t irq_id;
|
||||
uint64_t irq_id;
|
||||
uint8_t _via_ifr;
|
||||
uint8_t _via_ier;
|
||||
uint8_t old_ifr = 0;
|
||||
@@ -213,7 +225,10 @@ private:
|
||||
int32_t out_count;
|
||||
int32_t out_pos;
|
||||
uint8_t poll_rate;
|
||||
int32_t real_time = 0;
|
||||
uint32_t last_time = 0;
|
||||
uint32_t time_offset = 0;
|
||||
std::chrono::time_point<std::chrono::system_clock> mac_epoch;
|
||||
uint8_t one_sec_mode = 0;
|
||||
bool file_server;
|
||||
uint16_t device_mask = 0;
|
||||
|
||||
@@ -246,7 +261,8 @@ private:
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command();
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
void pseudo_command();
|
||||
uint32_t calc_real_time();
|
||||
|
||||
void null_out_handler(void);
|
||||
void pram_out_handler(void);
|
||||
@@ -257,8 +273,8 @@ private:
|
||||
|
||||
/* I2C related methods */
|
||||
void i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(
|
||||
uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1,
|
||||
const uint8_t* in_buf, int in_bytes);
|
||||
};
|
||||
|
||||
#endif /* VIACUDA_H */
|
||||
#endif // VIACUDA_H
|
||||
@@ -36,7 +36,7 @@ bool DeviceRegistry::add(const std::string name, DeviceDescription desc)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceRegistry::device_registered(const string dev_name)
|
||||
bool DeviceRegistry::device_registered(const std::string dev_name)
|
||||
{
|
||||
if (get_registry().find(dev_name) != get_registry().end()) {
|
||||
return true;
|
||||
@@ -45,7 +45,7 @@ bool DeviceRegistry::device_registered(const string dev_name)
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
|
||||
std::unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
|
||||
{
|
||||
auto it = get_registry().find(name);
|
||||
if (it != get_registry().end()) {
|
||||
|
||||
@@ -34,12 +34,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
class HWComponent;
|
||||
|
||||
typedef std::function<unique_ptr<HWComponent> ()> CreateFunc;
|
||||
typedef std::function<std::unique_ptr<HWComponent> ()> CreateFunc;
|
||||
|
||||
struct DeviceDescription {
|
||||
CreateFunc m_create_func;
|
||||
vector<string> subdev_list;
|
||||
PropMap properties;
|
||||
CreateFunc m_create_func;
|
||||
std::vector<std::string> subdev_list;
|
||||
PropMap properties;
|
||||
};
|
||||
|
||||
class DeviceRegistry
|
||||
@@ -47,17 +47,17 @@ class DeviceRegistry
|
||||
public:
|
||||
DeviceRegistry() = delete;
|
||||
|
||||
static bool add(const string name, DeviceDescription desc);
|
||||
static bool add(const std::string name, DeviceDescription desc);
|
||||
|
||||
static bool device_registered(const string dev_name);
|
||||
static bool device_registered(const std::string dev_name);
|
||||
|
||||
static unique_ptr<HWComponent> create(const string& name);
|
||||
static std::unique_ptr<HWComponent> create(const std::string& name);
|
||||
|
||||
static DeviceDescription& get_descriptor(const std::string& name);
|
||||
|
||||
private:
|
||||
static map<string, DeviceDescription> & get_registry() {
|
||||
static map<string, DeviceDescription> device_registry;
|
||||
static std::map<std::string, DeviceDescription> & get_registry() {
|
||||
static std::map<std::string, DeviceDescription> device_registry;
|
||||
return device_registry;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,21 +41,41 @@ enum BigMacReg : uint16_t {
|
||||
TX_FIFO_CSR = 0x100,
|
||||
TX_FIFO_TH = 0x110,
|
||||
RX_FIFO_CSR = 0x120,
|
||||
MEM_ADD = 0x130, // Memory Address
|
||||
MEM_DATA_HI = 0x140, // Memory Data High
|
||||
MEM_DATA_LO = 0x150, // Memory Data Low
|
||||
XCVR_IF = 0x160, // Transceiver IF Control
|
||||
CHIP_ID = 0x170,
|
||||
MIF_CSR = 0x180,
|
||||
SROM_CSR = 0x190,
|
||||
TX_PNTR = 0x1A0, // Apple: TX Pointer
|
||||
RX_PNTR = 0x1B0, // Apple: RX Pointer
|
||||
GLOB_STAT = 0x200, // Apple: kSTAT, Sun: Global Status Register
|
||||
EVENT_MASK = 0x210, // ambiguously called INT_DISABLE in the Apple source
|
||||
SROM_CSR = 0x190,
|
||||
TX_SW_RST = 0x420,
|
||||
TX_CONFIG = 0x430,
|
||||
IPG_1 = 0x440, // Inter Packet Gap 1
|
||||
IPG_2 = 0x450,
|
||||
A_LIMIT = 0x460, // Attempt Limit
|
||||
SLOT = 0x470,
|
||||
PA_LEN = 0x480, // Apple: PA Len, Sun: PA Size
|
||||
PA_PAT = 0x490,
|
||||
TX_SFD = 0x4A0,
|
||||
JAM_SIZE = 0x4B0,
|
||||
TX_MAX = 0x4C0, // Max frame size
|
||||
TX_MIN = 0x4D0, // Min frame size
|
||||
PEAK_ATT = 0x4E0, // Apple: kPAREG, Sun: PeakAttempts Register
|
||||
DEFER_TMR = 0x4F0, // Also called DCNT by Apple
|
||||
NC_CNT = 0x500, // Normal Collision Counter
|
||||
NT_CNT = 0x510, // Apple: Network Collision Counter
|
||||
EX_CNT = 0x520, // Excessive Collision Counter
|
||||
LT_CNT = 0x530, // Late Collision Counter
|
||||
RNG_SEED = 0x540,
|
||||
TX_SM = 0x550,
|
||||
RX_SW_RST = 0x620,
|
||||
RX_CONFIG = 0x630,
|
||||
RX_MAX = 0x640,
|
||||
RX_MIN = 0x650,
|
||||
MAC_ADDR_2 = 0x660,
|
||||
MAC_ADDR_1 = 0x670,
|
||||
MAC_ADDR_0 = 0x680,
|
||||
@@ -63,11 +83,16 @@ enum BigMacReg : uint16_t {
|
||||
RX_LE_CNT = 0x6A0, // Length Error Counter
|
||||
RX_AE_CNT = 0x6B0, // Alignment Error Counter
|
||||
RX_FE_CNT = 0x6C0, // FCS Error Counter
|
||||
RX_ST_MCHN = 0x6D0, // RX State Machine
|
||||
RX_CVE_CNT = 0x6E0, // Code Violation Error Counter
|
||||
HASH_TAB_3 = 0x700,
|
||||
HASH_TAB_2 = 0x710,
|
||||
HASH_TAB_1 = 0x720,
|
||||
HASH_TAB_0 = 0x730,
|
||||
AFR_2 = 0x740, // Address Filter 2
|
||||
AFR_1 = 0x750, // Address Filter 1
|
||||
AFR_0 = 0x760, // Address Filter 0
|
||||
AFC_R = 0x770, // Address Filter Mask
|
||||
};
|
||||
|
||||
/* MIF_CSR bit definitions. */
|
||||
|
||||
+65
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,11 +32,24 @@ using namespace MaceEnet;
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
return this->rcv_fc;
|
||||
case MaceReg::Interrupt: {
|
||||
uint8_t ret_val = this->int_stat;
|
||||
this->int_stat = 0;
|
||||
LOG_F(9, "%s: all interrupt flags cleared", this->name.c_str());
|
||||
return ret_val;
|
||||
}
|
||||
case MaceReg::Interrupt_Mask:
|
||||
return this->int_mask;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
return this->biu_ctrl;
|
||||
case MaceReg::Chip_ID_Lo:
|
||||
return this->chip_id & 0xFFU;
|
||||
case MaceReg::Chip_ID_Hi:
|
||||
return (this->chip_id >> 8) & 0xFFU;
|
||||
default:
|
||||
LOG_F(INFO, "Reading MACE register %d", reg_offset);
|
||||
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -45,15 +58,57 @@ uint8_t MaceController::read(uint8_t reg_offset)
|
||||
void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
this->rcv_fc = value;
|
||||
break;
|
||||
case MaceReg::Interrupt_Mask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
case MaceReg::MAC_Config_Ctrl:
|
||||
this->mac_cfg = value;
|
||||
break;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
if (value & 1) {
|
||||
LOG_F(INFO, "MACE Reset issued");
|
||||
} else {
|
||||
LOG_F(INFO, "MACE BIU Config set to 0x%X", value);
|
||||
if (value & BIU_SWRST) {
|
||||
LOG_F(INFO, "%s: soft reset asserted", this->name.c_str());
|
||||
value &= ~BIU_SWRST; // acknowledge soft reset
|
||||
}
|
||||
this->biu_ctrl = value;
|
||||
break;
|
||||
case MaceReg::PLS_Config_Ctrl:
|
||||
if (value != 7)
|
||||
LOG_F(WARNING, "%s: unsupported transceiver interface 0x%X in PLSCC",
|
||||
this->name.c_str(), value);
|
||||
break;
|
||||
case MaceReg::Int_Addr_Config:
|
||||
if ((value & IAC_LOGADDR) && (value & IAC_PHYADDR))
|
||||
value &= ~IAC_PHYADDR;
|
||||
if (value & (IAC_LOGADDR | IAC_PHYADDR))
|
||||
this->addr_ptr = 0;
|
||||
this->addr_cfg = value;
|
||||
break;
|
||||
case MaceReg::Log_Addr_Flt:
|
||||
if (this->addr_cfg & IAC_LOGADDR) {
|
||||
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
|
||||
this->log_addr = (this->log_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
|
||||
if (++this->addr_ptr >= 8) {
|
||||
this->addr_cfg &= ~IAC_LOGADDR;
|
||||
this->addr_ptr = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MaceReg::Phys_Addr:
|
||||
if (this->addr_cfg & IAC_PHYADDR) {
|
||||
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
|
||||
this->phys_addr = (this->phys_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
|
||||
if (++this->addr_ptr >= 6) {
|
||||
this->addr_cfg &= ~IAC_PHYADDR;
|
||||
this->addr_ptr = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
LOG_F(INFO, "%s: writing 0x%X to register %d", this->name.c_str(),
|
||||
value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+64
-37
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,58 +24,74 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
/** Known MACE chip IDs. */
|
||||
constexpr auto MACE_ID_REV_B0 = 0x0940; // Darwin-0.3 source
|
||||
constexpr auto MACE_ID_REV_A2 = 0x0941; // Darwin-0.3 source & Curio datasheet
|
||||
|
||||
// MACE registers offsets
|
||||
/** MACE registers offsets. */
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
namespace MaceEnet {
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 10,
|
||||
BIU_Config_Ctrl = 11,
|
||||
FIFO_Config = 12,
|
||||
MAC_Config_Ctrl = 13,
|
||||
PLS_Config_Ctrl = 14,
|
||||
PHY_Config_Ctrl = 15,
|
||||
Chip_ID_Lo = 16,
|
||||
Chip_ID_Hi = 17,
|
||||
Int_Addr_Config = 18,
|
||||
Log_Addr_Flt = 20,
|
||||
Phys_Addr = 21,
|
||||
Missed_Pkt_Cnt = 24,
|
||||
Runt_Pkt_Cnt = 26, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 27, // not used in Macintosh?
|
||||
User_Test = 29,
|
||||
Rsrvd_Test_1 = 30, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 31, // not used in Macintosh?
|
||||
};
|
||||
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 0x0A,
|
||||
BIU_Config_Ctrl = 0x0B,
|
||||
FIFO_Config = 0x0C,
|
||||
MAC_Config_Ctrl = 0x0D,
|
||||
PLS_Config_Ctrl = 0x0E,
|
||||
PHY_Config_Ctrl = 0x0F,
|
||||
Chip_ID_Lo = 0x10,
|
||||
Chip_ID_Hi = 0x11,
|
||||
Addr_Config = 0x12,
|
||||
Log_Addr_Flt = 0x14,
|
||||
Phys_Addr = 0x15,
|
||||
Missed_Pkt_Cnt = 0x18,
|
||||
Runt_Pkt_Cnt = 0x1A, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 0x1B, // not used in Macintosh?
|
||||
User_Test = 0x1D,
|
||||
Rsrvd_Test_1 = 0x1E, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
|
||||
};
|
||||
/** Bit definitions for BIU_Config_Ctrl register. */
|
||||
enum {
|
||||
BIU_SWRST = 1 << 0,
|
||||
};
|
||||
|
||||
/** Bit definitions for the internal configuration register. */
|
||||
enum {
|
||||
IAC_LOGADDR = 1 << 1,
|
||||
IAC_PHYADDR = 1 << 2,
|
||||
IAC_ADDRCHG = 1 << 7
|
||||
};
|
||||
|
||||
}; // namespace MaceEnet
|
||||
|
||||
class MaceController : public HWComponent {
|
||||
class MaceController : public DmaDevice, public HWComponent {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
MaceController(uint16_t id) {
|
||||
this->chip_id = id;
|
||||
this->set_name("MACE");
|
||||
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
|
||||
};
|
||||
~MaceController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID));
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID_REV_A2));
|
||||
}
|
||||
|
||||
// MACE registers access
|
||||
@@ -84,6 +100,17 @@ public:
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
uint8_t addr_cfg = 0;
|
||||
uint8_t addr_ptr = 0;
|
||||
uint8_t rcv_fc = 1;
|
||||
uint8_t biu_ctrl = 0;
|
||||
uint8_t mac_cfg = 0;
|
||||
uint64_t phys_addr = 0;
|
||||
uint64_t log_addr = 0;
|
||||
|
||||
// interrupt stuff
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t int_mask = 0;
|
||||
};
|
||||
|
||||
#endif // MACE_H
|
||||
@@ -311,7 +311,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
}
|
||||
|
||||
if (fconv->calc_phys_params()) {
|
||||
if (fconv && fconv->calc_phys_params()) {
|
||||
delete fconv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
#define BLOCK_SIZE 512 // size in bytes of a logical block
|
||||
constexpr auto BLOCK_SIZE = 512; // size in bytes of a logical block
|
||||
|
||||
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
|
||||
|
||||
@@ -50,13 +50,33 @@ public:
|
||||
virtual int get_raw_disk_data(char* buf) = 0;
|
||||
virtual int export_data(void) = 0;
|
||||
|
||||
int get_data_size() { return this->data_size; };
|
||||
int get_disk_rec_method() { return this->rec_method; };
|
||||
int get_number_of_tracks() { return this->num_tracks; };
|
||||
int get_number_of_sides() { return this->num_sides; };
|
||||
int get_sectors_per_side() { return this->num_sectors; };
|
||||
int get_rec_density() { return this->density; };
|
||||
uint8_t get_format_byte() { return this->format_byte; };
|
||||
int get_data_size() const {
|
||||
return this->data_size;
|
||||
}
|
||||
|
||||
int get_disk_rec_method() const {
|
||||
return this->rec_method;
|
||||
}
|
||||
|
||||
int get_number_of_tracks() const {
|
||||
return this->num_tracks;
|
||||
}
|
||||
|
||||
int get_number_of_sides() const {
|
||||
return this->num_sides;
|
||||
}
|
||||
|
||||
int get_sectors_per_side() const {
|
||||
return this->num_sectors;
|
||||
}
|
||||
|
||||
int get_rec_density() const {
|
||||
return this->density;
|
||||
}
|
||||
|
||||
uint8_t get_format_byte() const {
|
||||
return this->format_byte;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string img_path;
|
||||
|
||||
@@ -30,9 +30,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace MacSuperdrive;
|
||||
|
||||
MacSuperDrive::MacSuperDrive()
|
||||
MacSuperDrive::MacSuperDrive(std::string name)
|
||||
{
|
||||
this->name = "Superdrive";
|
||||
this->set_name(name);
|
||||
this->supported_types = HWCompType::FLOPPY_DRV;
|
||||
|
||||
this->eject_latch = 0; // eject latch is off
|
||||
@@ -55,9 +55,7 @@ void MacSuperDrive::reset_params()
|
||||
|
||||
void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
{
|
||||
uint8_t new_motor_stat;
|
||||
|
||||
LOG_F(9, "Superdrive: command addr=0x%X, value=%d", addr, value);
|
||||
LOG_F(9, "%s: command addr=0x%X, value=%d", this->get_name().c_str(), addr, value);
|
||||
|
||||
switch(addr) {
|
||||
case CommandAddr::Step_Direction:
|
||||
@@ -68,33 +66,24 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
this->cur_track += this->step_dir;
|
||||
if (this->cur_track < 0)
|
||||
this->cur_track = 0;
|
||||
else if (this->cur_track >= this->num_tracks) {
|
||||
LOG_F(ERROR, "%s: track:%d is greater than max track:%d",
|
||||
this->get_name().c_str(), this->cur_track, this->num_tracks - 1);
|
||||
this->cur_track = this->num_tracks - 1;
|
||||
}
|
||||
this->track_zero = this->cur_track == 0;
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Motor_On_Off:
|
||||
new_motor_stat = value ^ 1;
|
||||
if (this->motor_stat != new_motor_stat) {
|
||||
this->motor_stat = new_motor_stat;
|
||||
if (new_motor_stat) {
|
||||
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
|
||||
this->track_start_time = 0;
|
||||
this->sector_start_time = 0;
|
||||
this->init_track_search(-1);
|
||||
this->is_ready = 1;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor on");
|
||||
} else {
|
||||
this->motor_on_time = 0;
|
||||
this->is_ready = 0;
|
||||
LOG_F(INFO, "Superdrive: turn spindle motor off");
|
||||
}
|
||||
}
|
||||
this->set_motor_stat(value ^ 1);
|
||||
break;
|
||||
case CommandAddr::Eject_Disk:
|
||||
if (value) {
|
||||
LOG_F(INFO, "Superdrive: disk ejected");
|
||||
LOG_F(INFO, "%s: disk ejected", this->get_name().c_str());
|
||||
this->eject_latch = 1;
|
||||
this->reset_params();
|
||||
}
|
||||
break;
|
||||
case CommandAddr::Reset_Eject_Latch:
|
||||
if (value) {
|
||||
this->eject_latch = 0;
|
||||
@@ -107,53 +96,88 @@ void MacSuperDrive::command(uint8_t addr, uint8_t value)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented command, addr=0x%X", addr);
|
||||
LOG_F(WARNING, "%s: unimplemented command, addr=0x%X", this->get_name().c_str(), addr);
|
||||
}
|
||||
}
|
||||
|
||||
void MacSuperDrive::set_motor_stat(uint8_t new_motor_stat)
|
||||
{
|
||||
if (this->motor_stat != new_motor_stat) {
|
||||
this->motor_stat = new_motor_stat;
|
||||
if (new_motor_stat) {
|
||||
this->motor_on_time = TimerManager::get_instance()->current_time_ns();
|
||||
this->track_start_time = 0;
|
||||
this->sector_start_time = 0;
|
||||
this->init_track_search(-1);
|
||||
this->is_ready = 1;
|
||||
LOG_F(INFO, "%s: turn spindle motor on", this->get_name().c_str());
|
||||
} else {
|
||||
this->motor_on_time = 0;
|
||||
this->is_ready = 0;
|
||||
LOG_F(INFO, "%s: turn spindle motor off", this->get_name().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
{
|
||||
LOG_F(9, "Superdrive: status request, addr = 0x%X", addr);
|
||||
LOG_F(9, "%s: status request, addr = 0x%X", this->get_name().c_str(), addr);
|
||||
uint8_t value;
|
||||
|
||||
switch(addr) {
|
||||
case StatusAddr::Step_Status:
|
||||
return 1; // not sure what should be returned here
|
||||
value = 1; // not sure what should be returned here
|
||||
break;
|
||||
case StatusAddr::Motor_Status:
|
||||
return this->motor_stat ^ 1; // reverse logic
|
||||
value = this->motor_stat ^ 1; // reverse logic
|
||||
break;
|
||||
case StatusAddr::Eject_Latch:
|
||||
return this->eject_latch;
|
||||
value = this->eject_latch;
|
||||
break;
|
||||
case StatusAddr::Select_Head_0:
|
||||
return this->cur_head = 0;
|
||||
value = this->cur_head = 0;
|
||||
break;
|
||||
case StatusAddr::MFM_Support:
|
||||
return 1; // Superdrive does support MFM encoding scheme
|
||||
value = 1; // Superdrive does support MFM encoding scheme
|
||||
break;
|
||||
case StatusAddr::Double_Sided:
|
||||
return 1; // yes, Superdrive is double sided
|
||||
value = 1; // yes, Superdrive is double sided
|
||||
break;
|
||||
case StatusAddr::Drive_Exists:
|
||||
return 0; // tell the world I'm here
|
||||
value = 0; // tell the world I'm here
|
||||
break;
|
||||
case StatusAddr::Disk_In_Drive:
|
||||
return this->has_disk ^ 1; // reverse logic (active low)!
|
||||
value = this->has_disk ^ 1; // reverse logic (active low)!
|
||||
break;
|
||||
case StatusAddr::Write_Protect:
|
||||
return this->wr_protect ^ 1; // reverse logic
|
||||
value = this->wr_protect ^ 1; // reverse logic
|
||||
break;
|
||||
case StatusAddr::Track_Zero:
|
||||
return this->track_zero ^ 1; // reverse logic
|
||||
value = this->track_zero ^ 1; // reverse logic
|
||||
break;
|
||||
case StatusAddr::Select_Head_1:
|
||||
return this->cur_head = 1;
|
||||
value = this->cur_head = 1;
|
||||
break;
|
||||
case StatusAddr::Drive_Mode:
|
||||
return this->drive_mode;
|
||||
value = this->drive_mode;
|
||||
break;
|
||||
case StatusAddr::Drive_Ready:
|
||||
return this->is_ready ^ 1; // reverse logic
|
||||
value = this->is_ready ^ 1; // reverse logic
|
||||
break;
|
||||
case StatusAddr::Media_Kind:
|
||||
return this->media_kind ^ 1; // reverse logic!
|
||||
value = this->media_kind ^ 1; // reverse logic!
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Superdrive: unimplemented status request, addr=0x%X", addr);
|
||||
return 0;
|
||||
LOG_F(WARNING, "%s: unimplemented status request, addr=0x%X", this->get_name().c_str(), addr);
|
||||
value = 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int MacSuperDrive::insert_disk(std::string& img_path, int write_flag = 0)
|
||||
{
|
||||
if (this->has_disk) {
|
||||
LOG_F(ERROR, "Superdrive: drive is not empty!");
|
||||
LOG_F(ERROR, "%s: drive is not empty!", this->get_name().c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -250,7 +274,7 @@ void MacSuperDrive::init_track_search(int pos)
|
||||
// pick random sector number
|
||||
uint64_t seed = TimerManager::get_instance()->current_time_ns() >> 8;
|
||||
this->cur_sector = seed % this->sectors_per_track[this->cur_track];
|
||||
LOG_F(9, "Superdrive: current sector number set to %d", this->cur_sector);
|
||||
LOG_F(9, "%s: current sector number set to %d", this->get_name().c_str(), this->cur_sector);
|
||||
} else {
|
||||
this->cur_sector = pos;
|
||||
}
|
||||
@@ -260,7 +284,7 @@ uint64_t MacSuperDrive::sync_to_disk()
|
||||
{
|
||||
uint64_t cur_time_ns, track_time_ns;
|
||||
|
||||
uint64_t track_delay = this->get_current_track_delay() * NS_PER_SEC;
|
||||
uint64_t track_delay = uint64_t(this->get_current_track_delay() * NS_PER_SEC);
|
||||
|
||||
// look how much ns have been elapsed since the last motor enabling
|
||||
cur_time_ns = TimerManager::get_instance()->current_time_ns() - this->motor_on_time;
|
||||
|
||||
@@ -96,12 +96,13 @@ typedef struct SectorHdr {
|
||||
|
||||
class MacSuperDrive : public HWComponent {
|
||||
public:
|
||||
MacSuperDrive();
|
||||
MacSuperDrive(std::string name);
|
||||
~MacSuperDrive() = default;
|
||||
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
uint8_t status(uint8_t addr);
|
||||
int insert_disk(std::string& img_path, int write_flag);
|
||||
void set_motor_stat(uint8_t new_motor_stat);
|
||||
void init_track_search(int pos);
|
||||
uint64_t sync_to_disk();
|
||||
uint64_t next_addr_mark_delay(uint8_t *next_sect_num);
|
||||
|
||||
+38
-14
@@ -42,6 +42,16 @@ Swim3Ctrl::Swim3Ctrl()
|
||||
this->name = "SWIM3";
|
||||
this->supported_types = HWCompType::FLOPPY_CTRL;
|
||||
|
||||
this->reset();
|
||||
|
||||
// Attach virtual Superdrive to the internal drive connector
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive("Superdrive1"));
|
||||
}
|
||||
|
||||
void Swim3Ctrl::reset()
|
||||
{
|
||||
this->setup_reg = 0;
|
||||
this->mode_reg = 0;
|
||||
this->int_reg = 0;
|
||||
@@ -54,10 +64,24 @@ Swim3Ctrl::Swim3Ctrl()
|
||||
|
||||
this->cur_state = SWIM3_IDLE;
|
||||
|
||||
// Attach virtual Superdrive to the internal drive connector
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive());
|
||||
this->cur_track = 0xFF;
|
||||
this->cur_sector = 0x7F;
|
||||
|
||||
this->timer_val = 0;
|
||||
this->phase_lines = 0;
|
||||
|
||||
if (this->one_us_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->one_us_timer_id);
|
||||
this->one_us_timer_id = 0;
|
||||
}
|
||||
if (this->step_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
|
||||
this->step_timer_id = 0;
|
||||
}
|
||||
if (this->access_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Swim3Ctrl::device_postinit()
|
||||
@@ -92,8 +116,8 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
case Swim3Reg::Setup:
|
||||
return this->setup_reg;
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
if (this->mode_reg & SWIM3_DRIVE_1) { // internal drive?
|
||||
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
|
||||
rddata_val = this->int_drive->status(status_addr) & 1;
|
||||
|
||||
// transfer rddata_val to both bit 2 (RDDATA) and bit 3 (SENSE)
|
||||
@@ -128,7 +152,7 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
|
||||
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint8_t status_addr;
|
||||
uint8_t status_addr = 0;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Timer:
|
||||
@@ -140,14 +164,14 @@ void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
|
||||
case Swim3Reg::Phase:
|
||||
this->phase_lines = value & 0xF;
|
||||
if (this->phase_lines & 8) { // CA3 aka LSTRB high -> sending a command to the drive
|
||||
if (this->mode_reg & 2) { // if internal drive is selected
|
||||
if (this->mode_reg & SWIM3_DRIVE_1) { // if internal drive is selected
|
||||
this->int_drive->command(
|
||||
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
|
||||
((this->mode_reg & SWIM3_HEAD_SELECT) >> 3) | (this->phase_lines & 3),
|
||||
(value >> 2) & 1
|
||||
);
|
||||
}
|
||||
} else if (this->phase_lines == 4 && (this->mode_reg & 2)) {
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
} else if (this->phase_lines == 4 && (this->mode_reg & SWIM3_DRIVE_1)) {
|
||||
status_addr = ((this->mode_reg & SWIM3_HEAD_SELECT) >> 2) | (this->phase_lines & 7);
|
||||
this->rd_line = this->int_drive->status(status_addr) & 1;
|
||||
}
|
||||
break;
|
||||
@@ -239,7 +263,7 @@ void Swim3Ctrl::start_stepping()
|
||||
return;
|
||||
}
|
||||
|
||||
if ((((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3))
|
||||
if ((((this->mode_reg & SWIM3_HEAD_SELECT) >> 3) | (this->phase_lines & 3))
|
||||
!= MacSuperdrive::CommandAddr::Do_Step) {
|
||||
LOG_F(WARNING, "SWIM3: invalid command address on the phase lines!");
|
||||
return;
|
||||
@@ -376,7 +400,7 @@ void Swim3Ctrl::init_timer(const uint8_t start_val)
|
||||
this->one_us_timer_start = TimerManager::get_instance()->current_time_ns();
|
||||
|
||||
this->one_us_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
this->timer_val * NS_PER_USEC,
|
||||
uint32_t(this->timer_val) * NS_PER_USEC,
|
||||
[this]() {
|
||||
this->timer_val = 0;
|
||||
this->int_flags |= INT_TIMER_DONE;
|
||||
@@ -410,7 +434,7 @@ static const PropMap Swim3_Properties = {
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot",
|
||||
new BinProperty(0)},
|
||||
new BinProperty(1)},
|
||||
{"fdd_fmt",
|
||||
new StrProperty("", FloppyFormats)},
|
||||
};
|
||||
|
||||
Loaded 100 of 213 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user