Compare commits
1370 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
738a242e3c | ||
|
|
5fd6dc6dd4 | ||
|
|
3fd9cacb6d | ||
|
|
bb07a7334f | ||
|
|
748b771618 | ||
|
|
d6e72080d9 | ||
|
|
70109fed2c | ||
|
|
cf36d21daf | ||
|
|
781cd85b00 | ||
|
|
514537a983 | ||
|
|
184f4587fb | ||
|
|
e096aaabc4 | ||
|
|
ba26ae0f1c | ||
|
|
786adf0268 | ||
|
|
2af05220c2 | ||
|
|
362c4ffff1 | ||
|
|
95fd4e763b | ||
|
|
768e587b76 | ||
|
|
e3bb1c1b63 | ||
|
|
4c01bb453c | ||
|
|
dc67d438dc | ||
|
|
2d58ec4c86 | ||
|
|
555286ea47 | ||
|
|
b17eb66d55 | ||
|
|
9ca52054cf | ||
|
|
991f51831d | ||
|
|
e69f89a0d4 | ||
|
|
9411a8c186 | ||
|
|
dc4de4ce6f | ||
|
|
4e12453fff | ||
|
|
3a0418e279 | ||
|
|
1899bf377b | ||
|
|
0471002d4c | ||
|
|
704e08dc23 | ||
|
|
905837468c | ||
|
|
19d95782e1 | ||
|
|
adda19ecb2 | ||
|
|
b02d0346fd | ||
|
|
9097276a06 | ||
|
|
e99ab11c6f | ||
|
|
a564d8536a | ||
|
|
a21eee9207 | ||
|
|
71cddef78f | ||
|
|
9ae913064c | ||
|
|
a2313d1c03 | ||
|
|
22db3445a0 | ||
|
|
6417720d7d | ||
|
|
8b10906d90 | ||
|
|
0c55324d11 | ||
|
|
0b4fdc6e66 | ||
|
|
d3e62df769 | ||
|
|
04bd881cfa | ||
|
|
96799455cb | ||
|
|
814792eb91 | ||
|
|
2834bae318 | ||
|
|
037fae99d6 | ||
|
|
49c8888948 | ||
|
|
1875556f81 | ||
|
|
00850bf691 | ||
|
|
09fd199487 | ||
|
|
32c53578e0 | ||
|
|
0da90f61fc | ||
|
|
9942e8b299 | ||
|
|
daaeb97834 | ||
|
|
92da214066 | ||
|
|
0f05dd5c0a | ||
|
|
166bdbeb7d | ||
|
|
7dc2b7123b | ||
|
|
3d0ec9b785 | ||
|
|
85cfa5cba6 | ||
|
|
fdc1eaa16c | ||
|
|
d4dcf1a3e9 | ||
|
|
43fd137d55 | ||
|
|
6931eadc34 | ||
|
|
3143e7e1d0 | ||
|
|
d03396d272 | ||
|
|
c8aa2e8a89 | ||
|
|
c7a3a0278c | ||
|
|
5924f60d06 | ||
|
|
cd68b66c03 | ||
|
|
44cd3928fb | ||
|
|
8c54613e44 | ||
|
|
7dfa83b8c0 | ||
|
|
b551061264 | ||
|
|
3e228c33c9 | ||
|
|
2b23be8f44 | ||
|
|
ced78cb072 | ||
|
|
fb17850c3d | ||
|
|
7f7c4852cc | ||
|
|
f334e3b951 | ||
|
|
9d62995799 | ||
|
|
1d8b793cf7 | ||
|
|
33431cb939 | ||
|
|
e677e0142c | ||
|
|
b313a4aa2f | ||
|
|
37c5c6f049 | ||
|
|
a6d92ed8fe | ||
|
|
eb37ac4142 | ||
|
|
a0d4b96915 | ||
|
|
31891efbca | ||
|
|
58f3edda12 | ||
|
|
4a655384e2 | ||
|
|
0543c208fd | ||
|
|
0e834ec004 | ||
|
|
26454dc832 | ||
|
|
5c16836626 | ||
|
|
67e28b2a82 | ||
|
|
c2a2893b5c | ||
|
|
68b670f94f | ||
|
|
5a83a46423 | ||
|
|
8785fd0236 | ||
|
|
a67e8e60c6 | ||
|
|
c7551a731c | ||
|
|
d9c5437902 | ||
|
|
55d51217d8 | ||
|
|
11c9caaf13 | ||
|
|
c4711e5e3a | ||
|
|
d34f0a8eca | ||
|
|
8233d4e226 | ||
|
|
ca49956219 | ||
|
|
5edfbfc1f7 | ||
|
|
dfd50d9d75 | ||
|
|
1946941340 | ||
|
|
31dae90dcd | ||
|
|
da8df54649 | ||
|
|
0e1415299a | ||
|
|
93f770888d | ||
|
|
0886b10619 | ||
|
|
e8493d18c5 | ||
|
|
60a8bf56c6 | ||
|
|
c95b59c72e | ||
|
|
7e14c83bdd | ||
|
|
a2e46919c1 | ||
|
|
a4befc29c8 | ||
|
|
93e87284aa | ||
|
|
236dbb043c | ||
|
|
77f0295a04 | ||
|
|
c3b97999f5 | ||
|
|
3061001fb1 | ||
|
|
0bc51d5c34 | ||
|
|
c913de1e67 | ||
|
|
c9a578734e | ||
|
|
37544a0eb9 | ||
|
|
3ad314a5ac | ||
|
|
58a6a25eb3 | ||
|
|
6ed93a1f09 | ||
|
|
76dbdf45cf | ||
|
|
d4e1da0174 | ||
|
|
fde3b70d03 | ||
|
|
8c03702c7d | ||
|
|
31c6ead2ad | ||
|
|
454fa16b3a | ||
|
|
301e84f1ca | ||
|
|
69634fdbd5 | ||
|
|
10e823a9d5 | ||
|
|
f4851cd533 | ||
|
|
39287d43e3 | ||
|
|
09b2bf5fb1 | ||
|
|
e989309771 | ||
|
|
d989c45c3d | ||
|
|
84c5cf0661 | ||
|
|
648541bb1f | ||
|
|
2cf04e8a83 | ||
|
|
af10782500 | ||
|
|
fe0e5ae83d | ||
|
|
8e4af5c823 | ||
|
|
570a8d5222 | ||
|
|
2c8a1eb5c6 | ||
|
|
23c40aeb8e | ||
|
|
c7c832a0dd | ||
|
|
6423d0c1b3 | ||
|
|
8b56098d64 | ||
|
|
2927bd5aa3 | ||
|
|
d357db25f2 | ||
|
|
9b3cc5391b | ||
|
|
54eeb97b24 | ||
|
|
593f50de91 | ||
|
|
85af8d9fa4 | ||
|
|
58ff96dc83 | ||
|
|
a5803d1b62 | ||
|
|
eddb0988a0 | ||
|
|
5d3585a33d | ||
|
|
4285736286 | ||
|
|
32b8cf6172 | ||
|
|
3e724e88a8 | ||
|
|
687dfddd9f | ||
|
|
90a43089ba | ||
|
|
1e0baeb30e | ||
|
|
353f7d1705 | ||
|
|
f5f3764f99 | ||
|
|
eef22f8701 | ||
|
|
9e1a9f2842 | ||
|
|
0b33134f6c | ||
|
|
5c4d6c68b2 | ||
|
|
89e42a457c | ||
|
|
17ca09346d | ||
|
|
54de645dc3 | ||
|
|
da6c02068b | ||
|
|
06bcb39721 | ||
|
|
2b31a4ab5c | ||
|
|
3b4ef682fe | ||
|
|
eab9a31dff | ||
|
|
ff86ed2e77 | ||
|
|
2fe1169423 | ||
|
|
4c9fe186d7 | ||
|
|
e11cc090b2 | ||
|
|
763a1de8d3 | ||
|
|
e57b546dd4 | ||
|
|
bd670cf87c | ||
|
|
1e0996c395 | ||
|
|
5f295c4227 | ||
|
|
4f699ccb81 | ||
|
|
70757e564d | ||
|
|
af822e5af5 | ||
|
|
63736d7873 | ||
|
|
fb800bd4c9 | ||
|
|
219f38169f | ||
|
|
c688600d33 | ||
|
|
ea14d8a186 | ||
|
|
cd18b85632 | ||
|
|
22ec031495 | ||
|
|
43b998d37d | ||
|
|
127101a683 | ||
|
|
5955ca6957 | ||
|
|
dcddcfc94d | ||
|
|
1453d9adac | ||
|
|
ef034a87d4 | ||
|
|
e688ec9257 | ||
|
|
ae1f85d341 | ||
|
|
7177799021 | ||
|
|
1041d7c438 | ||
|
|
e57abad52f | ||
|
|
74bbfb95d3 | ||
|
|
8345f31c2a | ||
|
|
d44055d232 | ||
|
|
4a431b8fdf | ||
|
|
e2ed200509 | ||
|
|
4e5f6e1eff | ||
|
|
474eb3001b | ||
|
|
f72d99d9b0 | ||
|
|
a9a569c79d | ||
|
|
68b8c99ad0 | ||
|
|
d8c6f94887 | ||
|
|
8b51141f54 | ||
|
|
0195ab34e9 | ||
|
|
0bb82feb81 | ||
|
|
6199f598e5 | ||
|
|
b92406afe2 | ||
|
|
244409fc98 | ||
|
|
f3b2a6c30d | ||
|
|
a65f7fbf88 | ||
|
|
35ad240018 | ||
|
|
e64f267e4c | ||
|
|
d28e961adc | ||
|
|
e6b7dc1dc5 | ||
|
|
9e7e967a5f | ||
|
|
33d40b491e | ||
|
|
7cb50d38b9 | ||
|
|
d6d440a47e | ||
|
|
52cd950ca6 | ||
|
|
9fad2dff21 | ||
|
|
4b40dd52f4 | ||
|
|
6bd7070d38 | ||
|
|
0c9365bcb7 | ||
|
|
c0bd69309a | ||
|
|
55bd62d7a9 | ||
|
|
020236742f | ||
|
|
faeb0d9395 | ||
|
|
b05f993221 | ||
|
|
e796abb155 | ||
|
|
3d2c12cf09 | ||
|
|
8ff5111e30 | ||
|
|
673ec9fc51 | ||
|
|
a7100a1e7f | ||
|
|
710ad11819 | ||
|
|
f718297591 | ||
|
|
1c7b55ee1e | ||
|
|
f437d92374 | ||
|
|
47916b2831 | ||
|
|
0791aabbf8 | ||
|
|
bd15f51af3 | ||
|
|
932ed4222f | ||
|
|
1052e04679 | ||
|
|
3903ac6409 | ||
|
|
53622d777b | ||
|
|
2219b19d5f | ||
|
|
bc06b17823 | ||
|
|
89cc6ede1a | ||
|
|
dd6e071dde | ||
|
|
2127271b33 | ||
|
|
1600171ffa | ||
|
|
7f7a9fab2d | ||
|
|
b15d86f31d | ||
|
|
89a3dc8643 | ||
|
|
3477beb05c | ||
|
|
8447c209a7 | ||
|
|
e78f706c1a | ||
|
|
f776c56cd4 | ||
|
|
dc195dffad | ||
|
|
74a0b2feae | ||
|
|
71039fc248 | ||
|
|
d0306609c3 | ||
|
|
d13cde3d7b | ||
|
|
38f54fd2b6 | ||
|
|
b5728e9c11 | ||
|
|
a2177c0510 | ||
|
|
356a94cc2e | ||
|
|
9d507e046c | ||
|
|
47c47f967a | ||
|
|
1182d3a627 | ||
|
|
938cb6492f | ||
|
|
fed62855cb | ||
|
|
4f54596658 | ||
|
|
0b41ed04d5 | ||
|
|
9509a86998 | ||
|
|
6d4d80a798 | ||
|
|
76d274cfe2 | ||
|
|
ccf13be964 | ||
|
|
e36b27ccf0 | ||
|
|
34c80ad476 | ||
|
|
97ae106d8e | ||
|
|
7cb74b74d7 | ||
|
|
337205eb08 | ||
|
|
f36977017b | ||
|
|
e40b547bb6 | ||
|
|
1fd689f5da | ||
|
|
c5c8dca14c | ||
|
|
11f820efa7 | ||
|
|
9074688491 | ||
|
|
1de27c54f1 | ||
|
|
3e67e64faa | ||
|
|
553f8d2533 | ||
|
|
ec7ae35da1 | ||
|
|
7e8da0d236 | ||
|
|
b3e6561072 | ||
|
|
41f32ed983 | ||
|
|
bbadf840ef | ||
|
|
acc50aae46 | ||
|
|
6a68a77973 | ||
|
|
0f4d66dd61 | ||
|
|
d28642d2c3 | ||
|
|
ca4685cc42 | ||
|
|
522f10582d | ||
|
|
239d113177 | ||
|
|
fd80294bf2 | ||
|
|
b379d83469 | ||
|
|
27f352fdf1 | ||
|
|
bfec874a7c | ||
|
|
93561003e8 | ||
|
|
1572bfd989 | ||
|
|
cb945612a3 | ||
|
|
1b440f7f3b | ||
|
|
78791f7b66 | ||
|
|
5def0c18e2 | ||
|
|
0e67b0f026 | ||
|
|
8052946517 | ||
|
|
b6d6cc9750 | ||
|
|
2a840f2c79 | ||
|
|
4eaf791849 | ||
|
|
be0f50b19c | ||
|
|
f30b7b9fb3 | ||
|
|
6a0f332e3c | ||
|
|
16530d3a52 | ||
|
|
20af9c6750 | ||
|
|
fee9f6b427 | ||
|
|
57d03d6333 | ||
|
|
0075fe2aa0 | ||
|
|
d54417ac0a | ||
|
|
648801d432 | ||
|
|
2be2826b0b | ||
|
|
37a9fa1bf4 | ||
|
|
65af93c8ce | ||
|
|
8353b84944 | ||
|
|
d6a89db495 | ||
|
|
f156aa8cdb | ||
|
|
f9adbcc9d9 | ||
|
|
cf8696ac70 | ||
|
|
9c5766f649 | ||
|
|
c9701f93b9 | ||
|
|
56e54cd110 | ||
|
|
55836b48af | ||
|
|
09bfdb9ee1 | ||
|
|
1c2e8dec11 | ||
|
|
506b16db37 | ||
|
|
8f03234e58 | ||
|
|
44b5e10323 | ||
|
|
48303604b0 | ||
|
|
ab2ddbc2ee | ||
|
|
9495bf30bf | ||
|
|
a4899a1bec | ||
|
|
882c6cf0d4 | ||
|
|
a5e18c82d1 | ||
|
|
22a8661fe1 | ||
|
|
8258a98647 | ||
|
|
76dde0e6db | ||
|
|
1a39cb27e4 | ||
|
|
95d2d0a6bd | ||
|
|
98d4345858 | ||
|
|
1e4431dcc9 | ||
|
|
348b175994 | ||
|
|
76f057dafb | ||
|
|
188400c5a9 | ||
|
|
a74d9c6d3e | ||
|
|
f8bcfb2f58 | ||
|
|
d63fc2bc82 | ||
|
|
8e31784996 | ||
|
|
f27cdb4543 | ||
|
|
a39adc8ac1 | ||
|
|
97bef66018 | ||
|
|
bb5518b0f6 | ||
|
|
ac73a96ce2 | ||
|
|
7075004e58 | ||
|
|
ddf8ba5116 | ||
|
|
f46773ba64 | ||
|
|
f67d333457 | ||
|
|
4116c1e00f | ||
|
|
bc1aa15dd7 | ||
|
|
ecd27f7eaa | ||
|
|
618ce671ac | ||
|
|
2a6a655804 | ||
|
|
33436ae2a6 | ||
|
|
9f2b66ac51 | ||
|
|
df93e4797e | ||
|
|
538d1dec77 | ||
|
|
2492c8273a | ||
|
|
d358df48a6 | ||
|
|
f619dafff1 | ||
|
|
0419fc4e30 | ||
|
|
13317b9548 | ||
|
|
18db70a669 | ||
|
|
f79923814d | ||
|
|
c92de03a5f | ||
|
|
3f356da879 | ||
|
|
9efac01c86 | ||
|
|
ca2622af7c | ||
|
|
aa8e0bda8c | ||
|
|
c79f11ee99 | ||
|
|
04d0770b90 | ||
|
|
fbf8a1b6d9 | ||
|
|
a3cb6a622d | ||
|
|
0790a3ceb3 | ||
|
|
4fa12f90fc | ||
|
|
d5d56e7634 | ||
|
|
a964089df4 | ||
|
|
5fd5b4da89 | ||
|
|
322a7050aa | ||
|
|
b7f4ac02c8 | ||
|
|
009f61a8b6 | ||
|
|
26d0cafb39 | ||
|
|
bd1d4a77fe | ||
|
|
f235bc83a8 | ||
|
|
9c6b540905 | ||
|
|
d2e911a58e | ||
|
|
9344a7b434 | ||
|
|
cd194fa5b2 | ||
|
|
49c0ab65df | ||
|
|
8f9c1305e4 | ||
|
|
d4193ec11d | ||
|
|
6b9b0472bc | ||
|
|
7e74258363 | ||
|
|
f6483ec602 | ||
|
|
36c1da1d61 | ||
|
|
6bcb1f8679 | ||
|
|
62932a9639 | ||
|
|
a4629e4b65 | ||
|
|
a0c2b43b34 | ||
|
|
3907c46980 | ||
|
|
7e7ab124a3 | ||
|
|
cfc6cf24bf | ||
|
|
46e9cb6b23 | ||
|
|
ba14efe1f4 | ||
|
|
3d8f62d38f | ||
|
|
3edaf0af64 | ||
|
|
9273a88db7 | ||
|
|
37ba2c15de | ||
|
|
557f2057f7 | ||
|
|
6b5cc93780 | ||
|
|
9760191af8 | ||
|
|
8845e4dd20 | ||
|
|
8cf823f548 | ||
|
|
2538769f3a | ||
|
|
89fca38807 | ||
|
|
dcc0eed69c | ||
|
|
817475257e | ||
|
|
f2861058ba | ||
|
|
5d2a7315d5 | ||
|
|
1520ab7555 | ||
|
|
d4d0fbd73b | ||
|
|
ddb8e98e95 | ||
|
|
fd69b4169f | ||
|
|
b48e0b5c5b | ||
|
|
31e2243c5c | ||
|
|
da0ee2e442 | ||
|
|
b88dc9ac6a | ||
|
|
9f78d7f62b | ||
|
|
e67c6ed3ee | ||
|
|
2e111ca91b | ||
|
|
62d51fd99d | ||
|
|
a9289b1f21 | ||
|
|
d42e938232 | ||
|
|
3d3dcb1f28 | ||
|
|
82143212ce | ||
|
|
7246a2664e | ||
|
|
1291f2520a | ||
|
|
042ecf5343 | ||
|
|
6e54dcc24c | ||
|
|
91378ef3c1 | ||
|
|
0377cbd2b4 | ||
|
|
786ecf4fe4 | ||
|
|
0fbdee313f | ||
|
|
9b8e2b933d | ||
|
|
cc64ef9670 | ||
|
|
31ff6a1da8 | ||
|
|
94532e9cea | ||
|
|
3f93bc5988 | ||
|
|
39ca23d609 | ||
|
|
47a9c1b576 | ||
|
|
d819cfd58f | ||
|
|
17828273a5 | ||
|
|
2363817265 | ||
|
|
b31018ab17 | ||
|
|
c610ec3319 | ||
|
|
b71dedccfc | ||
|
|
9ccfacd06d | ||
|
|
12b561a27d | ||
|
|
cc41003e1c | ||
|
|
3d534c9a81 | ||
|
|
24de7c5272 | ||
|
|
a1b2ea2c5b | ||
|
|
19d68b6df4 | ||
|
|
2ab41dbd01 | ||
|
|
da30c0b0f0 | ||
|
|
005684d865 | ||
|
|
da1eff82ba | ||
|
|
a17311c955 | ||
|
|
e1d0602f25 | ||
|
|
2ff9718510 | ||
|
|
33af9cfe09 | ||
|
|
79709a7ae7 | ||
|
|
a796a70d01 | ||
|
|
53e2ef24f1 | ||
|
|
c0059c83ac | ||
|
|
37eb21d297 | ||
|
|
52a18831a7 | ||
|
|
0d7cca7b20 | ||
|
|
bea73c51ae | ||
|
|
0c68750056 | ||
|
|
ae8ea7da16 | ||
|
|
69762c5dce | ||
|
|
901d4992c0 | ||
|
|
4d47d891d1 | ||
|
|
a7046909ec | ||
|
|
4bc95979de | ||
|
|
949d219c72 | ||
|
|
9a3d9aed30 | ||
|
|
4d99143da0 | ||
|
|
461035b212 | ||
|
|
0694ea8367 | ||
|
|
427a05997d | ||
|
|
84d736c2eb | ||
|
|
a16d1ebe33 | ||
|
|
43f3c84316 | ||
|
|
44cafe3f46 | ||
|
|
76d7a035bd | ||
|
|
a5b638ae7b | ||
|
|
174089e4f3 | ||
|
|
4d219813fe | ||
|
|
a798f453d2 | ||
|
|
6ec21611c0 | ||
|
|
31f4419eec | ||
|
|
60d136f9b5 | ||
|
|
0ba7f9dba0 | ||
|
|
0ac6db006a | ||
|
|
26dd61e4e6 | ||
|
|
dda11206db | ||
|
|
e8565d30a9 | ||
|
|
2d4c103854 | ||
|
|
d0b9e36908 | ||
|
|
21db0d45bd | ||
|
|
4429cb2095 | ||
|
|
cab54d1b31 | ||
|
|
1d2909ea03 | ||
|
|
d802e5329c | ||
|
|
118f81d347 | ||
|
|
ba3740a77a | ||
|
|
47369c8f5e | ||
|
|
7a05dee453 | ||
|
|
9e47369365 | ||
|
|
5379c05001 | ||
|
|
5b34b2d114 | ||
|
|
3ea8734fdd | ||
|
|
8e22080e05 | ||
|
|
692a94fe5e | ||
|
|
01c760ab88 | ||
|
|
28e5d8107f | ||
|
|
710d8cd15c | ||
|
|
8395540288 | ||
|
|
d57d8aaae7 | ||
|
|
10f555b6fb | ||
|
|
9f30244bfb | ||
|
|
0b65fcbdd7 | ||
|
|
067e217909 | ||
|
|
d6c6c421e9 | ||
|
|
90b54581b0 | ||
|
|
68d9674ca3 | ||
|
|
a9a8edeaf4 | ||
|
|
dd21a3930d | ||
|
|
53209b9be0 | ||
|
|
8308e1a8b8 | ||
|
|
986a2fb5d8 | ||
|
|
9570e6cbec | ||
|
|
93a08c5ef9 | ||
|
|
a187c0c7ce | ||
|
|
43f4475272 | ||
|
|
a7ed32e206 | ||
|
|
6eadac23b3 | ||
|
|
1c7eb8f97a | ||
|
|
a71c5f42fc | ||
|
|
de0f1dc156 | ||
|
|
bb05961f70 | ||
|
|
57900e91ba | ||
|
|
98f650a5de | ||
|
|
55b2db4a8d | ||
|
|
fbe3088744 | ||
|
|
336ab6a64c | ||
|
|
c73fec46e6 | ||
|
|
b493e2bd5f | ||
|
|
78a7d6c5af | ||
|
|
a8b2e9a50c | ||
|
|
2d7c1e42d8 | ||
|
|
64ebec3ea4 | ||
|
|
252d32aafe | ||
|
|
2349370960 | ||
|
|
6ccc0f0538 | ||
|
|
9f12a47cfc | ||
|
|
ee880802c8 | ||
|
|
ab14e77b50 | ||
|
|
1d4245e582 | ||
|
|
8636a74ba4 | ||
|
|
3b766de306 | ||
|
|
1f300e1b75 | ||
|
|
56efe6035f | ||
|
|
73e363d159 | ||
|
|
3ac134bc16 | ||
|
|
c7bb1f9655 | ||
|
|
7847646b3e | ||
|
|
ec6e9f73bb | ||
|
|
bd62f033ab | ||
|
|
ba88ec25f6 | ||
|
|
b9bc41a772 | ||
|
|
e029458b09 | ||
|
|
b3ecf1776b | ||
|
|
5fe83588eb | ||
|
|
18b8eaabae | ||
|
|
e11695c2f0 | ||
|
|
91edbf71c8 | ||
|
|
5b9b22021b | ||
|
|
033d90b866 | ||
|
|
540c0df918 | ||
|
|
6de167467f | ||
|
|
c746326eb3 | ||
|
|
0fbd384a73 | ||
|
|
e8d4a98c7b | ||
|
|
f5aa63936c | ||
|
|
62a57d0f47 | ||
|
|
958fb4c739 | ||
|
|
e231275cbe | ||
|
|
5a404c3a35 | ||
|
|
b1c07c6204 | ||
|
|
60f158d488 | ||
|
|
1887c6fae3 | ||
|
|
725a825762 | ||
|
|
b81f59d5ae | ||
|
|
39c2b8927b | ||
|
|
89dfdac7bf | ||
|
|
c087edf2ba | ||
|
|
db33c315f2 | ||
|
|
c7e7dd8248 | ||
|
|
b10d82a883 | ||
|
|
e151b3d4ef | ||
|
|
5ccf4a45c1 | ||
|
|
c5369a5cad | ||
|
|
b5eba765a5 | ||
|
|
a5ddc38477 | ||
|
|
8d102256a2 | ||
|
|
2e561f7ea9 | ||
|
|
9656fe1b6f | ||
|
|
48c23f2a43 | ||
|
|
6d82649c3c | ||
|
|
81dea35754 | ||
|
|
fdbe43421b | ||
|
|
0d71560785 | ||
|
|
108e8a0cd4 | ||
|
|
653e81c48e | ||
|
|
0dc0783094 | ||
|
|
13ef1bf6be | ||
|
|
7ea80353f6 | ||
|
|
07bbff7d11 | ||
|
|
2ff4fc3cdd | ||
|
|
c9456055ea | ||
|
|
2900f2d67b | ||
|
|
93c8c90804 | ||
|
|
36e54642d2 | ||
|
|
e04cb28711 | ||
|
|
ad1dc51e06 | ||
|
|
5b6bab7a58 | ||
|
|
9bd2fc659d | ||
|
|
f18633f65f | ||
|
|
1026bc7b4f | ||
|
|
f1dee68142 | ||
|
|
f7cc2d295c | ||
|
|
a6f254b5cf | ||
|
|
00dbbe1b28 | ||
|
|
7f33309903 | ||
|
|
c95808fa2d | ||
|
|
5b6bd048a9 | ||
|
|
28e6ad3372 | ||
|
|
9b128ebba5 | ||
|
|
71f49180c3 | ||
|
|
4a042241a8 | ||
|
|
0eab9127e3 | ||
|
|
9f11991410 | ||
|
|
fec0b95098 | ||
|
|
5081439f53 | ||
|
|
c44aebee4d | ||
|
|
706cd50f25 | ||
|
|
b1b81c87f2 | ||
|
|
bf7e30539e | ||
|
|
5f8a61201b | ||
|
|
ed8aee8b8c | ||
|
|
92ec2af587 | ||
|
|
7960c87579 | ||
|
|
700d572732 | ||
|
|
014a0d86f1 | ||
|
|
88db59405f | ||
|
|
ef2e008700 | ||
|
|
07101c053a | ||
|
|
6c5f6ac475 | ||
|
|
61ecd9a617 | ||
|
|
6f56a9bfe9 | ||
|
|
416875ee46 | ||
|
|
c875b506ea | ||
|
|
ff4517e583 | ||
|
|
92cc989dc9 | ||
|
|
6e5987e3ca | ||
|
|
f03e232b90 | ||
|
|
1eb18c1790 | ||
|
|
3076d56973 | ||
|
|
b35707edf9 | ||
|
|
dfbd0dc9e7 | ||
|
|
620ad7ba71 | ||
|
|
5e4fd53243 | ||
|
|
0ba7630354 | ||
|
|
028d0ec0d5 | ||
|
|
751fa05fcd | ||
|
|
f89845257e | ||
|
|
2f274e2f47 | ||
|
|
38088e80e1 | ||
|
|
14162828ea | ||
|
|
ab8507e09d | ||
|
|
0d25c07333 | ||
|
|
bfc8ba8447 | ||
|
|
a45f8293d9 | ||
|
|
f29b9d14d7 | ||
|
|
9c9fd2deef | ||
|
|
3bb01ffd68 | ||
|
|
bc6d9994dc | ||
|
|
e177f9e0fe | ||
|
|
c5d75d2de9 | ||
|
|
cc0cade4d2 | ||
|
|
1e3362250f | ||
|
|
db16e8d602 | ||
|
|
2a563eddd0 | ||
|
|
6b8474b7b9 | ||
|
|
b5336c81cc | ||
|
|
1fcab825bf | ||
|
|
0306556032 | ||
|
|
b093578046 | ||
|
|
9332b9eb33 | ||
|
|
141c7817a0 | ||
|
|
f155026d8f | ||
|
|
37e467ba60 | ||
|
|
3572b835b5 | ||
|
|
da4f3a72af | ||
|
|
2938bbd11f | ||
|
|
abf3017eb2 | ||
|
|
5c855ea52f | ||
|
|
c83edea7ad | ||
|
|
6d3113c8c3 | ||
|
|
48c48c7bbc | ||
|
|
e4093ed988 | ||
|
|
c79af52720 | ||
|
|
61eeaca6d5 | ||
|
|
320a79ba72 | ||
|
|
2e1b943805 | ||
|
|
bc167dde2d | ||
|
|
7d9a8b4211 | ||
|
|
0b16d88756 | ||
|
|
796cb31ed7 | ||
|
|
d7fd2f26c1 | ||
|
|
5adb8749de | ||
|
|
3474faa4a2 | ||
|
|
acd9c04ff6 | ||
|
|
833c9406b0 | ||
|
|
2f1253e27f | ||
|
|
53b847e31c | ||
|
|
7efa33dd7f | ||
|
|
4011970a57 | ||
|
|
a2cfa2be16 | ||
|
|
c4b691d688 | ||
|
|
72a7a8eee5 | ||
|
|
52d352385f | ||
|
|
c1f85650bd | ||
|
|
b830909504 | ||
|
|
4ad6b1c220 | ||
|
|
429488a4ba | ||
|
|
40c6cc11a5 | ||
|
|
594881c6ce | ||
|
|
1cc64a0fbc | ||
|
|
f492318e3c | ||
|
|
4b06bb7795 | ||
|
|
f7e570383a | ||
|
|
896a088199 | ||
|
|
f3322bd003 | ||
|
|
cef947d67d | ||
|
|
b6640d118d | ||
|
|
273d0b2ce9 | ||
|
|
9b724d776e | ||
|
|
3eaa706ccf | ||
|
|
b4c854dfe8 | ||
|
|
9cdadbe834 | ||
|
|
b3f38a8764 | ||
|
|
5d868284c6 | ||
|
|
035751980d | ||
|
|
6b80bc08d5 | ||
|
|
2089959d1b | ||
|
|
67b00ec28d | ||
|
|
127ae6b945 | ||
|
|
4f53b3ce35 | ||
|
|
c3092b482a | ||
|
|
080219f88d | ||
|
|
3fd783cd01 | ||
|
|
211cd964d7 | ||
|
|
04f42f0be4 | ||
|
|
e00ef893d0 | ||
|
|
858efa604e | ||
|
|
b63b17c54f | ||
|
|
f0e111c20e | ||
|
|
7339f57138 | ||
|
|
1e39c999f9 | ||
|
|
62f7a06192 | ||
|
|
a0531b7930 | ||
|
|
0619d04939 | ||
|
|
cd76476d26 | ||
|
|
53b6c17e33 | ||
|
|
3b7b66b272 | ||
|
|
a795a45c34 | ||
|
|
b58cbd228c | ||
|
|
fc994285f9 | ||
|
|
d5e74b91c7 | ||
|
|
c5eb2e1070 | ||
|
|
d613cb057e | ||
|
|
121792bebe | ||
|
|
e07c230106 | ||
|
|
d5ce3044c8 | ||
|
|
98ff43b4d2 | ||
|
|
1704fbcd62 | ||
|
|
014ac1cf72 | ||
|
|
b499c7ee75 | ||
|
|
2e069e326c | ||
|
|
e47d42da22 | ||
|
|
615e5dfaa7 | ||
|
|
fde2c371ef | ||
|
|
a0b4e7fd5d | ||
|
|
45c36bbcae | ||
|
|
66c041ad93 | ||
|
|
32d5c52b5f | ||
|
|
9cf5b01633 | ||
|
|
d4cf22d370 | ||
|
|
973640f023 | ||
|
|
248ea82f76 | ||
|
|
a868079a93 | ||
|
|
d270d5b9ca | ||
|
|
e9692a438b | ||
|
|
06ea123dbd | ||
|
|
85141d5eda | ||
|
|
fa13b8fbd0 | ||
|
|
5b4712644a | ||
|
|
aa422914bd | ||
|
|
22c453e297 | ||
|
|
e5f40cec5a | ||
|
|
50b24bf6c2 | ||
|
|
b575ee9e28 | ||
|
|
37030621ac | ||
|
|
f005da4d12 | ||
|
|
6295559d9c | ||
|
|
f36ff303d9 | ||
|
|
1a62e91c01 | ||
|
|
7f314dfe11 | ||
|
|
0caf9f4214 | ||
|
|
1ad600c81a | ||
|
|
bd6c7b7fdb | ||
|
|
5f93724845 | ||
|
|
ad60eac6ef | ||
|
|
b3e3a2937a | ||
|
|
d010038228 | ||
|
|
c28eada93e | ||
|
|
9d84a92b1f | ||
|
|
7884be106d | ||
|
|
5fe7c7e7e1 | ||
|
|
f244b95aad | ||
|
|
3b5a5759b8 | ||
|
|
528e7ee33b | ||
|
|
c1f55735fc | ||
|
|
185ea86284 | ||
|
|
618262f015 | ||
|
|
c0f41ac10e | ||
|
|
3010699f20 | ||
|
|
fb274538e1 | ||
|
|
1a5d953a98 | ||
|
|
2dd1baebb3 | ||
|
|
d46beac22a | ||
|
|
6ed8741006 | ||
|
|
6845e42f2c | ||
|
|
5196869634 | ||
|
|
083806bfc9 | ||
|
|
11d29368ce | ||
|
|
100c3d9e36 | ||
|
|
01fbf8c3a5 | ||
|
|
a36556d7e4 | ||
|
|
4f11162fae | ||
|
|
2cbaf39fd5 | ||
|
|
2cc46c618b | ||
|
|
a0325e91f9 | ||
|
|
e11edd5dee | ||
|
|
5e8990f571 | ||
|
|
a3fd55036a | ||
|
|
7a3d15c48b | ||
|
|
a5b52a2470 | ||
|
|
a8cd14dafd | ||
|
|
2b249bd496 | ||
|
|
c8586cfe26 | ||
|
|
f228cb241f | ||
|
|
fd33ef8496 | ||
|
|
ba1cf6473a | ||
|
|
f418dcdb7b | ||
|
|
f91c26d752 | ||
|
|
f7156f2ff2 | ||
|
|
e444b587cf | ||
|
|
a7fcc6a5cf | ||
|
|
872b1ccbb6 | ||
|
|
b7b3400296 | ||
|
|
420ccdcb82 | ||
|
|
eaa4d6323e | ||
|
|
4e7ac41a6c | ||
|
|
92f3a736a7 | ||
|
|
5a30b2b298 | ||
|
|
85aaae67bf | ||
|
|
efe66bc72e | ||
|
|
d7bdf3fc19 | ||
|
|
c4e5f4410c | ||
|
|
f5039dca56 | ||
|
|
de6f9789cb | ||
|
|
4376a1093f | ||
|
|
a413ed01f3 | ||
|
|
05bb831321 | ||
|
|
6e0f1e5235 | ||
|
|
2f915401dd | ||
|
|
14152b3072 | ||
|
|
8f3cba37b3 | ||
|
|
0853f6f7ad | ||
|
|
ae7a7ba365 | ||
|
|
724af0fdc4 | ||
|
|
550ea2116e | ||
|
|
7952271d61 | ||
|
|
ffaa5790c2 | ||
|
|
934c4bed0b | ||
|
|
6f040caa98 | ||
|
|
50e5c29b1c | ||
|
|
e0b5539b91 | ||
|
|
050f58a3bb | ||
|
|
c739ed8e48 | ||
|
|
a09fc6ebcb | ||
|
|
4367ea6afa | ||
|
|
da0adeb39e | ||
|
|
63160a22a6 | ||
|
|
2bc1927ebd | ||
|
|
66e0cfc185 | ||
|
|
7bd0e4f5b4 | ||
|
|
7271850df2 | ||
|
|
8c79285774 | ||
|
|
56a77ceac1 | ||
|
|
3034420ac2 | ||
|
|
99a157649d | ||
|
|
e6645554f0 | ||
|
|
0f83d1ffaa | ||
|
|
2286eb21a7 | ||
|
|
64c81aa5f8 | ||
|
|
29dcfca608 | ||
|
|
f1cb9630ec | ||
|
|
ebbea57400 | ||
|
|
6016dc14f8 | ||
|
|
dc8e4e5f14 | ||
|
|
72c8212a0e | ||
|
|
2cd2a081d6 | ||
|
|
b44ec544f4 | ||
|
|
063eae7e95 | ||
|
|
2552572904 | ||
|
|
b74dda42a2 | ||
|
|
6e178e2069 | ||
|
|
277d723992 | ||
|
|
2f6afe9932 | ||
|
|
edcc617780 | ||
|
|
5d39242b83 | ||
|
|
ddbe5fd27b | ||
|
|
deb91d1d02 | ||
|
|
63073ea07f | ||
|
|
a331fcd873 | ||
|
|
99654bd5b2 | ||
|
|
f10427287f | ||
|
|
5b6318ee3a | ||
|
|
98cdbe0784 | ||
|
|
e4eb3ae38d | ||
|
|
6686e4add7 | ||
|
|
96a274bf7d | ||
|
|
add17a7994 | ||
|
|
26e404c6a2 | ||
|
|
144de8b328 | ||
|
|
c0226e6fd9 | ||
|
|
57d728a9be | ||
|
|
b2e9f5377b | ||
|
|
d3d315784c | ||
|
|
942a371b6a | ||
|
|
66ffc78f60 | ||
|
|
a9570cef14 | ||
|
|
16bc08f046 | ||
|
|
024335e5cd | ||
|
|
8f32048774 | ||
|
|
33d3dd256d | ||
|
|
fc151f7595 | ||
|
|
9152884815 | ||
|
|
2b4e97bec5 | ||
|
|
a63393504f | ||
|
|
97ae8d2d44 | ||
|
|
6c59728516 | ||
|
|
201fe05a06 | ||
|
|
a78889523f | ||
|
|
5cd1a207c9 | ||
|
|
423f0ca631 | ||
|
|
7612e38d41 | ||
|
|
bf234950cb | ||
|
|
bd992fca15 | ||
|
|
45fee57abd | ||
|
|
a2bca96d47 | ||
|
|
9862256ca7 | ||
|
|
6afc8b3b5c | ||
|
|
9b4b4ec543 | ||
|
|
d412711868 | ||
|
|
0b33551d94 | ||
|
|
9c1b585054 | ||
|
|
fc3a69d9ca | ||
|
|
cce4a6d07f | ||
|
|
b16539408b | ||
|
|
eba56d0f64 | ||
|
|
f2181b1d3e | ||
|
|
c93a97f8d7 | ||
|
|
8fd2525cd1 | ||
|
|
62a70cfdac | ||
|
|
ca0a79fc89 | ||
|
|
104b8e859f | ||
|
|
a99b26ff8c | ||
|
|
9bc62ec12d | ||
|
|
84a6bb772f | ||
|
|
263a5eda56 | ||
|
|
7fb17ce52f | ||
|
|
631fad24c0 | ||
|
|
f1d77fa62a | ||
|
|
3bc247b43b | ||
|
|
3608799dff | ||
|
|
c0f042bc2a | ||
|
|
8982ff259a | ||
|
|
726b06b748 | ||
|
|
0057ab9c5a | ||
|
|
048bf0ee4d | ||
|
|
4da0708b51 | ||
|
|
4c529e3145 | ||
|
|
8ceeca372f | ||
|
|
4326ac9be1 | ||
|
|
697c64abe4 | ||
|
|
7e8cf84c42 | ||
|
|
b6d91375a5 | ||
|
|
61305688fd | ||
|
|
492ae4139f | ||
|
|
a84f393bd5 | ||
|
|
5de54d6f9f | ||
|
|
8fc797120f | ||
|
|
5406d648bc | ||
|
|
a2003fba95 | ||
|
|
a76c15d018 | ||
|
|
ae8caf3d3a | ||
|
|
f221915a95 | ||
|
|
7f93733107 | ||
|
|
e8b9e49f57 | ||
|
|
cb9576b10e | ||
|
|
06fe06f9f1 | ||
|
|
abf7c8e565 | ||
|
|
46227e6763 | ||
|
|
2ffe4a5451 | ||
|
|
18bd4bbcf6 | ||
|
|
8209433696 | ||
|
|
ad9e00acaa | ||
|
|
c96f96258f | ||
|
|
82699f3e00 | ||
|
|
e2d828a4a2 | ||
|
|
92328c6a7e | ||
|
|
3f8ad17e86 | ||
|
|
52999db43a | ||
|
|
760aa99709 | ||
|
|
51c514de84 | ||
|
|
317899b4bf | ||
|
|
4c93d2b1f9 | ||
|
|
71c5404bfe | ||
|
|
9c5248b87a | ||
|
|
83a0293af4 | ||
|
|
84f3eddaf8 | ||
|
|
a5c6b908b6 | ||
|
|
94f0d873df | ||
|
|
d6f66d24fa | ||
|
|
31458e9938 | ||
|
|
dca612ffd7 | ||
|
|
5177308d48 | ||
|
|
59ab44a8c7 | ||
|
|
c711ed6253 | ||
|
|
58c6be17eb | ||
|
|
259bcc686c | ||
|
|
356268eae5 | ||
|
|
2dd64b8a92 | ||
|
|
b5cddedb7d | ||
|
|
7afdc2b3b5 | ||
|
|
60c4956290 | ||
|
|
4c6a2f7ab1 | ||
|
|
76cee0d95b | ||
|
|
7331a919e4 | ||
|
|
27ea6b96c4 | ||
|
|
33238cee54 | ||
|
|
384dd2ad81 | ||
|
|
4885e0b8d8 | ||
|
|
2a84911d3b | ||
|
|
7f672fb417 | ||
|
|
a13fdeecf6 | ||
|
|
74ac76ba84 | ||
|
|
253e031f83 | ||
|
|
ef1ecf859c | ||
|
|
a302ad3bea | ||
|
|
0951260df7 | ||
|
|
b87dadbb72 | ||
|
|
1dd6a9821a | ||
|
|
50a2424001 | ||
|
|
61e5a4444f | ||
|
|
de3eb6ccd7 | ||
|
|
4f8c66b2b7 | ||
|
|
4d9cbc4e19 | ||
|
|
40369d44df | ||
|
|
ee3720f0b7 | ||
|
|
e5dcca1c2b | ||
|
|
ef8438a214 | ||
|
|
dfd699c16b | ||
|
|
a381c2a811 | ||
|
|
e4c87a59d0 | ||
|
|
eef30ceb3c | ||
|
|
76411387ba | ||
|
|
8d5d8d2100 | ||
|
|
802bce12a7 | ||
|
|
a1024c288e | ||
|
|
a4531b01d5 | ||
|
|
d445b20e90 | ||
|
|
24ddf5ca3d | ||
|
|
bb117d3d74 | ||
|
|
c101653077 | ||
|
|
5248b96f8a | ||
|
|
7ab59e420a | ||
|
|
83a849126a | ||
|
|
c9c373f607 | ||
|
|
aa7c2c0009 | ||
|
|
57fc4df86f | ||
|
|
75acdc8a98 | ||
|
|
070f7fcc68 | ||
|
|
4d48238fb1 | ||
|
|
9b304404f7 | ||
|
|
8e5ced8e3c | ||
|
|
95ef379ac5 | ||
|
|
915f9ccb0d | ||
|
|
3709ac301a | ||
|
|
3bc966f84e | ||
|
|
457b4cec13 | ||
|
|
88891ef6cd | ||
|
|
25811e2b52 | ||
|
|
f81c92e35b | ||
|
|
39b2aff627 | ||
|
|
905777466d | ||
|
|
4e21cf4f1c | ||
|
|
eccf9eab93 | ||
|
|
c36ad54bcb | ||
|
|
81e2b7c11c | ||
|
|
18b5cdcddf | ||
|
|
fe31114779 | ||
|
|
df30a2a320 | ||
|
|
cf7fa8ecbd | ||
|
|
389a169443 | ||
|
|
e01802e299 | ||
|
|
709aefba5d | ||
|
|
e4ed713fce | ||
|
|
d3c507b0d4 | ||
|
|
a68e14def3 | ||
|
|
8175642a2a | ||
|
|
8d1befea9e | ||
|
|
e7b8a0ef39 | ||
|
|
be6ee894f9 | ||
|
|
e0e8ed2113 | ||
|
|
c63e46b1a9 | ||
|
|
eb9c74a1ed | ||
|
|
efd83e063e | ||
|
|
ae23a1c84d | ||
|
|
fd1253caac | ||
|
|
a0e8bc1de3 | ||
|
|
004f0652c9 | ||
|
|
d5190cd788 | ||
|
|
2412faf033 | ||
|
|
72caad86cc | ||
|
|
7df9917a00 | ||
|
|
575adcbb9d | ||
|
|
2d6debddb9 | ||
|
|
53d2aac2ae | ||
|
|
96211813e3 | ||
|
|
153bbd6242 | ||
|
|
730e716f0f | ||
|
|
2238293c0f | ||
|
|
29d8e637d8 | ||
|
|
136e0d8974 | ||
|
|
0eb87df84f | ||
|
|
a9db998d84 | ||
|
|
fcb8edffdf | ||
|
|
61684ecb68 | ||
|
|
0ced86b55f | ||
|
|
159c9cb475 | ||
|
|
2943dcb2e9 | ||
|
|
984c3e549c | ||
|
|
edfd63e1f7 | ||
|
|
e593584a47 | ||
|
|
ef60c8ea4c | ||
|
|
e478908dca | ||
|
|
ca587692eb | ||
|
|
f78dd5365c | ||
|
|
f9d6cdccb0 | ||
|
|
35fdd470b3 | ||
|
|
edff11be7b | ||
|
|
bb230de72c | ||
|
|
2d7dde9cf9 | ||
|
|
b77d619873 | ||
|
|
ae1033d975 | ||
|
|
99d28c4f79 | ||
|
|
2424865fa1 | ||
|
|
6a280723f8 | ||
|
|
f85bbfff58 | ||
|
|
d239d82379 | ||
|
|
9017de6082 | ||
|
|
477414a636 | ||
|
|
5fac49447c | ||
|
|
30b3a51309 | ||
|
|
bafba1197e | ||
|
|
2fab0be5e8 | ||
|
|
7ea2a0a278 | ||
|
|
a3ae38520c | ||
|
|
c36fa01651 | ||
|
|
9aeac7af92 | ||
|
|
859944dc8e | ||
|
|
a6dc3c8fc7 | ||
|
|
61c02ed079 | ||
|
|
afc6f51ff2 | ||
|
|
c32eefaa51 | ||
|
|
b6969cf0d1 | ||
|
|
58a33ee6e9 | ||
|
|
050f433046 | ||
|
|
d48f6b62ce | ||
|
|
ffee64c67f | ||
|
|
8cbc535755 | ||
|
|
ca07af2fe9 | ||
|
|
2fe5da97eb | ||
|
|
6ffaeadd1b | ||
|
|
2c10b6bff2 | ||
|
|
76acfd9934 | ||
|
|
06cc4f7172 | ||
|
|
158659e5b0 | ||
|
|
7e46046e3b | ||
|
|
808c4b7361 | ||
|
|
03dc4fc425 | ||
|
|
b4029dcd73 | ||
|
|
1750b256eb | ||
|
|
d00d82ac89 | ||
|
|
edb5a82a89 | ||
|
|
f7552f7c32 | ||
|
|
4483b65b25 | ||
|
|
d2f53626ae | ||
|
|
ac01fe417e | ||
|
|
2fd8c7aace | ||
|
|
b90b138766 | ||
|
|
c3ad7eda08 | ||
|
|
02c6a3c214 | ||
|
|
8dd9c1a1af | ||
|
|
be54052b6d | ||
|
|
9e87679ee2 | ||
|
|
17964f8cd1 | ||
|
|
a63fb971d4 | ||
|
|
4b500349e6 | ||
|
|
8e554e17c9 | ||
|
|
1d77206ae4 | ||
|
|
4340c326dc | ||
|
|
c6cb97ae30 | ||
|
|
9d68c980e6 | ||
|
|
e2596a0a61 | ||
|
|
17d3c6491a | ||
|
|
f55fc421ea | ||
|
|
169b12fc20 | ||
|
|
905f816bbe | ||
|
|
fef48a449a | ||
|
|
95d06c115a | ||
|
|
113059e57c | ||
|
|
408c70b90c | ||
|
|
5b51574ebf | ||
|
|
1e6d7a5aee | ||
|
|
a28b50cee8 | ||
|
|
df112b550b | ||
|
|
85615d1916 | ||
|
|
c6d3158b56 | ||
|
|
4a4de608ec | ||
|
|
e651c3d9cc | ||
|
|
9c12496b30 | ||
|
|
bfc2448662 | ||
|
|
faa04b0309 | ||
|
|
ca1ea7fd6e | ||
|
|
57dc1b09ad | ||
|
|
5a9d0e2569 | ||
|
|
f6d3abbc11 | ||
|
|
041ca8451e | ||
|
|
9ab3a7c451 | ||
|
|
2382e6d82c | ||
|
|
f0e1937eeb | ||
|
|
efd08ff731 | ||
|
|
f9a1f1a79b | ||
|
|
a736e4602a | ||
|
|
5202ba8826 | ||
|
|
0f1bc98bb7 | ||
|
|
d40722af53 | ||
|
|
c9781ab626 | ||
|
|
4cbf4e93e7 | ||
|
|
1f68c2da42 | ||
|
|
d786c292f3 | ||
|
|
ada3e09784 | ||
|
|
c928b3b68b | ||
|
|
ae9c29629c | ||
|
|
3fd4603553 | ||
|
|
c14526068a | ||
|
|
180b2a6f4d | ||
|
|
b926ab7dd2 | ||
|
|
19d8861d27 | ||
|
|
70e82e627b | ||
|
|
67e229e5a9 | ||
|
|
d0d6baaa85 | ||
|
|
fd4352a1d6 | ||
|
|
08808da741 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.xml text eol=lf
|
||||
100
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
100
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Use this to report bugs you encounter with Luma3DS. Make sure you upload the crash dumps if Luma3DS crashes.
|
||||
---
|
||||
|
||||
<!--
|
||||
-- THIS IS NOT A SUPPORT FORUM! For support go here:
|
||||
-- Nintendo Homebrew: https://discord.gg/MjzatM8
|
||||
--
|
||||
-- Rosalina feature requests go here: https://github.com/LumaTeam/Luma3DS/issues/752
|
||||
--
|
||||
-- Also check the Wiki (https://github.com/LumaTeam/Luma3DS/wiki) before making an issue.
|
||||
--
|
||||
-- For GBA/DSiWare/DS/AGB_FIRM/TWL_FIRM problems: use https://github.com/MechanicalDragon0687/TWLFix-CFW and update your system.
|
||||
-- If you're using an emu/redNAND try installing anything on it to sysNAND.
|
||||
-- Please make sure to read "Enable game patching" https://github.com/LumaTeam/Luma3DS/wiki/Options-and-usage before posting any issues about the "Enable game patching" option(s).
|
||||
--
|
||||
-- Luma updaters that don't support Boot9Strap/Sighax won't work.
|
||||
-- This is due to support for non-B9S/Sighax entrypoints being dropped.
|
||||
--
|
||||
-- Please fill in the placeholders.-->
|
||||
**System model:**
|
||||
|
||||
[New 2DS XL, New 3DS XL, New 3DS, Old 2DS, Old 3DS XL, Old 3DS]
|
||||
|
||||
**SysNAND version (+emu/redNAND version if applicable):**
|
||||
|
||||
[e.g. 11.13.0-45U SysNAND, 11.13.0-45E EmuNAND]
|
||||
<!--You can check which version you're on in System Settings. It will be on the bottom right of the top screen.-->
|
||||
|
||||
**Entrypoint (How/what you're using to boot Luma3DS):**
|
||||
|
||||
[e.g. Boot9Strap/Sighax, etc.]
|
||||
|
||||
**Luma3DS version:**
|
||||
|
||||
[e.g. v10.2 stable or if using non-releases specify the commit like this https://github.com/LumaTeam/Luma3DS/commit/0543c208fd154e6326ea5da8cbf66ffcbdef010c]
|
||||
|
||||
**Luma3DS configuration/options:**
|
||||
|
||||
Default EmuNAND: ( )
|
||||
<!--This option is only available if there's at least one EmuNAND.-->
|
||||
|
||||
Screen brightness: ( )
|
||||
|
||||
Splash: ( )
|
||||
|
||||
Splash duration: ( )
|
||||
|
||||
PIN lock: ( )
|
||||
|
||||
New 3DS CPU: ( )
|
||||
<!--This option is only available on New 3DS (XL)/New 2DS XL.-->
|
||||
|
||||
--
|
||||
|
||||
Autoboot EmuNAND: ( )
|
||||
<!--This option is only available if there's at least one EmuNAND.-->
|
||||
|
||||
Use EmuNAND FIRM if booting with R: ( )
|
||||
<!--This option is only available if there's at least one EmuNAND.-->
|
||||
|
||||
Enable loading external FIRMs and modules: ( )
|
||||
<!--Firmware (.bin) files are not required by Luma, or NTR CFW anymore.
|
||||
-- If you're having issues with this option enabled try deleting them from the luma folder on the root of the SD card or /rw/luma on CTRNAND and disabling this option.-->
|
||||
|
||||
Enable game patching: ( )
|
||||
|
||||
Show NAND or user string in System Settings: ( )
|
||||
|
||||
Show GBA boot screen in patched AGB_FIRM: ( )
|
||||
|
||||
Set developer UNITINFO: ( )
|
||||
|
||||
Disable Arm11 exception handlers: ( )
|
||||
|
||||
Enable Rosalina on SAFE_FIRM: ( )
|
||||
<!--This option is only available on New 3DS (XL)/New 2DS XL.-->
|
||||
|
||||
--
|
||||
|
||||
|
||||
**Explanation of the issue:**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
**Steps to reproduce:**
|
||||
|
||||
1.
|
||||
|
||||
2.
|
||||
|
||||
|
||||
**Dump file:**
|
||||
<!--If the issue leads to a crash you must uncheck the "Disable Arm11 exception handlers" option.
|
||||
-- The error message will tell you where the dump is.
|
||||
-- Zip the dmp file and drag & drop it below.-->
|
||||
23
.gitignore
vendored
23
.gitignore
vendored
@@ -1,12 +1,23 @@
|
||||
.vscode
|
||||
out
|
||||
build
|
||||
loader/build
|
||||
screeninit/build
|
||||
injector/build
|
||||
arm11/build
|
||||
sysmodules/loader/build
|
||||
sysmodules/rosalina/build
|
||||
chainloader/build
|
||||
exceptions/arm9/build
|
||||
exceptions/arm11/build
|
||||
*.bin
|
||||
*.3dsx
|
||||
*.smdh
|
||||
*.firm
|
||||
*.o
|
||||
*.d
|
||||
*.elf
|
||||
*.bat
|
||||
*.cxi
|
||||
*.3dsx
|
||||
.DS_Store
|
||||
*.dmp
|
||||
.project
|
||||
.cproject
|
||||
.settings
|
||||
|
||||
Luma3DS*.zip
|
||||
|
||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,6 +0,0 @@
|
||||
[submodule "CakeBrah"]
|
||||
path = CakeBrah
|
||||
url = https://github.com/mid-kid/CakeBrah
|
||||
[submodule "CakeHax"]
|
||||
path = CakeHax
|
||||
url = https://github.com/mid-kid/CakeHax
|
||||
1
CakeBrah
1
CakeBrah
Submodule CakeBrah deleted from 42ebe0d0bc
1
CakeHax
1
CakeHax
Submodule CakeHax deleted from 6b8fca0b37
138
Makefile
138
Makefile
@@ -1,128 +1,34 @@
|
||||
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
ifneq ($(strip $(shell firmtool -v 2>&1 | grep usage)),)
|
||||
$(error "Please install firmtool v1.1 or greater")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/3ds_rules
|
||||
NAME := $(notdir $(CURDIR))
|
||||
REVISION := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
||||
|
||||
CC := arm-none-eabi-gcc
|
||||
AS := arm-none-eabi-as
|
||||
LD := arm-none-eabi-ld
|
||||
OC := arm-none-eabi-objcopy
|
||||
SUBFOLDERS := sysmodules arm11 arm9 k11_extension
|
||||
|
||||
name := AuReiNand
|
||||
version := $(shell git describe --abbrev=0 --tags)
|
||||
.PHONY: all release clean $(SUBFOLDERS)
|
||||
|
||||
dir_source := source
|
||||
dir_patches := patches
|
||||
dir_loader := loader
|
||||
dir_screeninit := screeninit
|
||||
dir_injector := injector
|
||||
dir_mset := CakeHax
|
||||
dir_ninjhax := CakeBrah
|
||||
dir_build := build
|
||||
dir_out := out
|
||||
all: boot.firm
|
||||
|
||||
ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
|
||||
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math
|
||||
LDFLAGS := -nostartfiles
|
||||
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Reisyukaku/Aurora Wright" --no-print-directory
|
||||
release: $(NAME)$(REVISION).zip
|
||||
|
||||
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
||||
$(call rwildcard, $(dir_source), *.s *.c)))
|
||||
|
||||
bundled = $(dir_build)/patches.h $(dir_build)/loader.h $(dir_build)/screeninit.h
|
||||
|
||||
.PHONY: all
|
||||
all: launcher a9lh ninjhax
|
||||
|
||||
.PHONY: launcher
|
||||
launcher: $(dir_out)/$(name).dat
|
||||
|
||||
.PHONY: a9lh
|
||||
a9lh: $(dir_out)/arm9loaderhax.bin
|
||||
|
||||
.PHONY: ninjhax
|
||||
ninjhax: $(dir_out)/3ds/$(name)
|
||||
|
||||
.PHONY: release
|
||||
release: $(dir_out)/$(name).zip
|
||||
|
||||
.PHONY: pathchanger
|
||||
pathchanger: $(dir_out)/pathchanger
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@$(MAKE) $(FLAGS) -C $(dir_mset) clean
|
||||
@$(MAKE) $(FLAGS) -C $(dir_ninjhax) clean
|
||||
@$(MAKE) -C $(dir_loader) clean
|
||||
@$(MAKE) -C $(dir_screeninit) clean
|
||||
@$(MAKE) -C $(dir_injector) clean
|
||||
@rm -rf $(dir_out) $(dir_build)
|
||||
@$(foreach dir, $(SUBFOLDERS), $(MAKE) -C $(dir) clean &&) true
|
||||
@rm -rf *.firm *.zip *.3dsx
|
||||
|
||||
$(dir_out):
|
||||
@mkdir -p "$(dir_out)/aurei/payloads"
|
||||
# boot.3dsx comes from https://github.com/fincs/new-hbmenu/releases
|
||||
$(NAME)$(REVISION).zip: boot.firm boot.3dsx
|
||||
@zip -r $@ $^ -x "*.DS_Store*" "*__MACOSX*"
|
||||
|
||||
$(dir_out)/pathchanger: $(dir_out)
|
||||
@cc pathchanger/pathchanger.c -o out/pathchanger
|
||||
boot.firm: $(SUBFOLDERS)
|
||||
@firmtool build $@ -D sysmodules/sysmodules.bin arm11/arm11.elf arm9/arm9.elf k11_extension/k11_extension.elf \
|
||||
-A 0x18180000 -C XDMA XDMA NDMA XDMA
|
||||
@echo built... $(notdir $@)
|
||||
|
||||
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)
|
||||
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher
|
||||
@dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144
|
||||
boot.3dsx:
|
||||
@curl -sSL "https://github.com/fincs/new-hbmenu/releases/latest/download/boot.3dsx" -o "$@"
|
||||
@echo downloaded... $(notdir $@)
|
||||
|
||||
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)
|
||||
@cp -a $(dir_build)/main.bin $@
|
||||
|
||||
$(dir_out)/3ds/$(name): $(dir_out)
|
||||
@mkdir -p "$@"
|
||||
@$(MAKE) $(FLAGS) -C $(dir_ninjhax)
|
||||
@mv $(dir_out)/$(name).3dsx $(dir_out)/$(name).smdh $@
|
||||
|
||||
$(dir_out)/$(name).zip: launcher a9lh ninjhax
|
||||
@cd "$(@D)" && zip -9 -r $(name) *
|
||||
|
||||
$(dir_build)/main.bin: $(dir_build)/main.elf
|
||||
$(OC) -S -O binary $< $@
|
||||
|
||||
$(dir_build)/main.elf: $(objects)
|
||||
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||
|
||||
$(dir_build)/patches.h: $(dir_patches)/emunand.s $(dir_patches)/reboot.s $(dir_injector)/Makefile
|
||||
@mkdir -p "$(@D)"
|
||||
@armips $<
|
||||
@armips $(word 2,$^)
|
||||
@$(MAKE) -C $(dir_injector)
|
||||
@mv emunand.bin reboot.bin $(dir_injector)/injector.cxi $(@D)
|
||||
@bin2c -o $@ -n emunand $(@D)/emunand.bin -n reboot $(@D)/reboot.bin -n injector $(@D)/injector.cxi
|
||||
|
||||
$(dir_build)/loader.h: $(dir_loader)/Makefile
|
||||
@$(MAKE) -C $(dir_loader)
|
||||
@mv $(dir_loader)/loader.bin $(@D)
|
||||
@bin2c -o $@ -n loader $(@D)/loader.bin
|
||||
|
||||
$(dir_build)/screeninit.h: $(dir_screeninit)/Makefile
|
||||
@$(MAKE) -C $(dir_screeninit)
|
||||
@mv $(dir_screeninit)/screeninit.bin $(@D)
|
||||
@bin2c -o $@ -n screeninit $(@D)/screeninit.bin
|
||||
|
||||
$(dir_build)/memory.o : CFLAGS += -O3
|
||||
$(dir_build)/config.o : CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\""
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.c $(bundled)
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.s
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||
|
||||
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.c
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
|
||||
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s
|
||||
@mkdir -p "$(@D)"
|
||||
$(COMPILE.s) $(OUTPUT_OPTION) $<
|
||||
include $(call rwildcard, $(dir_build), *.d)
|
||||
$(SUBFOLDERS):
|
||||
@$(MAKE) -C $@ all
|
||||
|
||||
42
README.md
42
README.md
@@ -1,16 +1,36 @@
|
||||
# AuReiNand
|
||||
*A modification of the ReiNand custom firmware*
|
||||
# Luma3DS
|
||||
*Noob-proof (N)3DS "Custom Firmware"*
|
||||
|
||||
**Compiling:**
|
||||
### What it is
|
||||
**Luma3DS** is a program to patch the system software of (New) Nintendo (2)3DS handheld consoles "on the fly", adding features such as per-game language settings, debugging capabilities for developers, and removing restrictions enforced by Nintendo such as the region lock.
|
||||
|
||||
You'll need armips, [bin2c](https://sourceforge.net/projects/bin2c/), and a recent build of [makerom](https://github.com/profi200/Project_CTR) added to your PATH. [HERE](http://www91.zippyshare.com/v/ePGpjk9r/file.html) is a pre-compiled version of armips for Windows.
|
||||
Then, just run "make" and everything should work!
|
||||
You can find the compiled files in the 'out' folder.
|
||||
It also allows you to run unauthorized ("homebrew") content by removing signature checks.
|
||||
To use it, you will need a console capable of running homebrew software on the Arm9 processor.
|
||||
|
||||
**Setup / Usage / Features:**
|
||||
Since v8.0, Luma3DS has its own in-game menu, triggerable by <kbd>L+Down+Select</kbd> (see the [release notes](https://github.com/LumaTeam/Luma3DS/releases/tag/v8.0)).
|
||||
|
||||
See https://github.com/AuroraWright/AuReiNand/wiki
|
||||
#
|
||||
### Compiling
|
||||
* Prerequisites
|
||||
1. git
|
||||
2. [makerom](https://github.com/jakcron/Project_CTR) in PATH
|
||||
3. [firmtool](https://github.com/TuxSH/firmtool)
|
||||
4. Up-to-date devkitARM+libctru
|
||||
1. Clone the repository with `git clone https://github.com/LumaTeam/Luma3DS.git`
|
||||
2. Run `make`.
|
||||
|
||||
**Credits:**
|
||||
|
||||
See https://github.com/AuroraWright/AuReiNand/wiki/Credits
|
||||
The produced `boot.firm` is meant to be copied to the root of your SD card for usage with Boot9Strap.
|
||||
|
||||
#
|
||||
### Setup / Usage / Features
|
||||
See https://github.com/LumaTeam/Luma3DS/wiki
|
||||
|
||||
#
|
||||
### Credits
|
||||
See https://github.com/LumaTeam/Luma3DS/wiki/Credits
|
||||
|
||||
#
|
||||
### Licensing
|
||||
This software is licensed under the terms of the GPLv3. You can find a copy of the license in the LICENSE.txt file.
|
||||
|
||||
Files in the GDB stub are instead triple-licensed as MIT or "GPLv2 or any later version", in which case it's specified in the file header.
|
||||
|
||||
147
arm11/Makefile
Normal file
147
arm11/Makefile
Normal file
@@ -0,0 +1,147 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITARM)/base_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source source/svc
|
||||
DATA := data
|
||||
INCLUDES := include include/svc
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||
DEFINES := -DARM11 -D_3DS
|
||||
|
||||
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
||||
-Wno-main -fno-builtin $(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE)
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS :=
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).bin
|
||||
|
||||
$(OUTPUT).bin : $(OUTPUT).elf
|
||||
$(OBJCOPY) -S -O binary $< $@
|
||||
@echo built ... $(notdir $@)
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
%.elf: $(OFILES)
|
||||
@echo linking $(notdir $@)
|
||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
||||
@$(NM) -CSn $@ > $(notdir $*.lst)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
158
arm11/linker.ld
Normal file
158
arm11/linker.ld
Normal file
@@ -0,0 +1,158 @@
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(_start)
|
||||
|
||||
/* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */
|
||||
|
||||
PHDRS
|
||||
{
|
||||
main PT_LOAD;
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
PROVIDE(__start__ = 0x1FF80000);
|
||||
PROVIDE(__stack_top__ = 0x1FFFE000);
|
||||
PROVIDE(__stack_bottom__ = 0x1FFFD000);
|
||||
|
||||
. = __start__;
|
||||
|
||||
.text :
|
||||
{
|
||||
KEEP( *(.text.start) )
|
||||
KEEP( *(.init) )
|
||||
|
||||
/* .text */
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
*(.stub)
|
||||
*(.gnu.warning)
|
||||
*(.gnu.linkonce.t*)
|
||||
|
||||
/* .fini */
|
||||
KEEP( *(.fini) )
|
||||
. = ALIGN(32);
|
||||
} :main
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.roda)
|
||||
*(.rodata.*)
|
||||
*all.rodata*(*)
|
||||
*(.gnu.linkonce.r*)
|
||||
SORT(CONSTRUCTORS)
|
||||
. = ALIGN(8);
|
||||
}
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE (__preinit_array_end = .);
|
||||
}
|
||||
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE (__init_array_end = .);
|
||||
}
|
||||
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE (__fini_array_start = .);
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE (__fini_array_end = .);
|
||||
}
|
||||
|
||||
.ctors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
||||
}
|
||||
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
||||
}
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = .;}
|
||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = .;}
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
KEEP (*(.large_patch*))
|
||||
*(.gnu.linkonce.d*)
|
||||
CONSTRUCTORS
|
||||
. = ALIGN(32);
|
||||
}
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(32);
|
||||
PROVIDE (__bss_start__ = ABSOLUTE(.));
|
||||
*(.dynbss)
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.gnu.linkonce.b*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__bss_end__ = ABSOLUTE(.));
|
||||
} :NONE
|
||||
|
||||
PROVIDE (__end__ = ABSOLUTE(.));
|
||||
|
||||
/* ==================
|
||||
==== Metadata ====
|
||||
================== */
|
||||
|
||||
/* Discard sections that difficult post-processing */
|
||||
/DISCARD/ : { *(.group .comment .note) }
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
|
||||
/* DWARF debug sections.
|
||||
Symbols in the DWARF debugging sections are relative to the beginning
|
||||
of the section so we begin them at 0. */
|
||||
|
||||
/* DWARF 1 */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
|
||||
/* GNU DWARF 1 extensions */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
|
||||
/* DWARF 1.1 and DWARF 2 */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
|
||||
/* DWARF 2 */
|
||||
.debug_info 0 : { *(.debug_info) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
}
|
||||
7
arm11/linker.specs
Normal file
7
arm11/linker.specs
Normal file
@@ -0,0 +1,7 @@
|
||||
%rename link old_link
|
||||
|
||||
*link:
|
||||
%(old_link) -T %:getenv(TOPDIR /linker.ld) --nmagic --gc-sections
|
||||
|
||||
*startfile:
|
||||
crti%O%s crtbegin%O%s
|
||||
232
arm11/source/main.c
Normal file
232
arm11/source/main.c
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others
|
||||
* LCD deinit code by tiniVi
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "memory.h"
|
||||
|
||||
void prepareForFirmlaunch(void);
|
||||
extern u32 prepareForFirmlaunchSize;
|
||||
|
||||
extern volatile Arm11Operation operation;
|
||||
|
||||
static void initScreens(u32 brightnessLevel, struct fb *fbs)
|
||||
{
|
||||
*(vu32 *)0x10141200 = 0x1007F;
|
||||
|
||||
*(vu32 *)0x10202204 = 0x01000000; //set LCD fill black to hide potential garbage -- NFIRM does it before firmlaunching
|
||||
*(vu32 *)0x10202A04 = 0x01000000;
|
||||
|
||||
*(vu32 *)0x10202014 = 0x00000001;
|
||||
*(vu32 *)0x1020200C &= 0xFFFEFFFE;
|
||||
*(vu32 *)0x10202240 = brightnessLevel;
|
||||
*(vu32 *)0x10202A40 = brightnessLevel;
|
||||
*(vu32 *)0x10202244 = 0x1023E;
|
||||
*(vu32 *)0x10202A44 = 0x1023E;
|
||||
|
||||
//Top screen
|
||||
*(vu32 *)0x10400400 = 0x000001c2;
|
||||
*(vu32 *)0x10400404 = 0x000000d1;
|
||||
*(vu32 *)0x10400408 = 0x000001c1;
|
||||
*(vu32 *)0x1040040c = 0x000001c1;
|
||||
*(vu32 *)0x10400410 = 0x00000000;
|
||||
*(vu32 *)0x10400414 = 0x000000cf;
|
||||
*(vu32 *)0x10400418 = 0x000000d1;
|
||||
*(vu32 *)0x1040041c = 0x01c501c1;
|
||||
*(vu32 *)0x10400420 = 0x00010000;
|
||||
*(vu32 *)0x10400424 = 0x0000019d;
|
||||
*(vu32 *)0x10400428 = 0x00000002;
|
||||
*(vu32 *)0x1040042c = 0x00000192;
|
||||
*(vu32 *)0x10400430 = 0x00000192;
|
||||
*(vu32 *)0x10400434 = 0x00000192;
|
||||
*(vu32 *)0x10400438 = 0x00000001;
|
||||
*(vu32 *)0x1040043c = 0x00000002;
|
||||
*(vu32 *)0x10400440 = 0x01960192;
|
||||
*(vu32 *)0x10400444 = 0x00000000;
|
||||
*(vu32 *)0x10400448 = 0x00000000;
|
||||
*(vu32 *)0x1040045C = 0x00f00190;
|
||||
*(vu32 *)0x10400460 = 0x01c100d1;
|
||||
*(vu32 *)0x10400464 = 0x01920002;
|
||||
*(vu32 *)0x10400468 = (u32)fbs[0].top_left;
|
||||
*(vu32 *)0x1040046C = (u32)fbs[1].top_left;
|
||||
*(vu32 *)0x10400470 = 0x80341;
|
||||
*(vu32 *)0x10400474 = 0x00010501;
|
||||
*(vu32 *)0x10400478 = 0;
|
||||
*(vu32 *)0x10400494 = (u32)fbs[0].top_right;
|
||||
*(vu32 *)0x10400498 = (u32)fbs[1].top_right;
|
||||
*(vu32 *)0x10400490 = 0x000002D0;
|
||||
*(vu32 *)0x1040049C = 0x00000000;
|
||||
|
||||
//Disco register
|
||||
for(u32 i = 0; i < 256; i++)
|
||||
*(vu32 *)0x10400484 = 0x10101 * i;
|
||||
|
||||
//Bottom screen
|
||||
*(vu32 *)0x10400500 = 0x000001c2;
|
||||
*(vu32 *)0x10400504 = 0x000000d1;
|
||||
*(vu32 *)0x10400508 = 0x000001c1;
|
||||
*(vu32 *)0x1040050c = 0x000001c1;
|
||||
*(vu32 *)0x10400510 = 0x000000cd;
|
||||
*(vu32 *)0x10400514 = 0x000000cf;
|
||||
*(vu32 *)0x10400518 = 0x000000d1;
|
||||
*(vu32 *)0x1040051c = 0x01c501c1;
|
||||
*(vu32 *)0x10400520 = 0x00010000;
|
||||
*(vu32 *)0x10400524 = 0x0000019d;
|
||||
*(vu32 *)0x10400528 = 0x00000052;
|
||||
*(vu32 *)0x1040052c = 0x00000192;
|
||||
*(vu32 *)0x10400530 = 0x00000192;
|
||||
*(vu32 *)0x10400534 = 0x0000004f;
|
||||
*(vu32 *)0x10400538 = 0x00000050;
|
||||
*(vu32 *)0x1040053c = 0x00000052;
|
||||
*(vu32 *)0x10400540 = 0x01980194;
|
||||
*(vu32 *)0x10400544 = 0x00000000;
|
||||
*(vu32 *)0x10400548 = 0x00000011;
|
||||
*(vu32 *)0x1040055C = 0x00f00140;
|
||||
*(vu32 *)0x10400560 = 0x01c100d1;
|
||||
*(vu32 *)0x10400564 = 0x01920052;
|
||||
*(vu32 *)0x10400568 = (u32)fbs[0].bottom;
|
||||
*(vu32 *)0x1040056C = (u32)fbs[1].bottom;
|
||||
*(vu32 *)0x10400570 = 0x80301;
|
||||
*(vu32 *)0x10400574 = 0x00010501;
|
||||
*(vu32 *)0x10400578 = 0;
|
||||
*(vu32 *)0x10400590 = 0x000002D0;
|
||||
*(vu32 *)0x1040059C = 0x00000000;
|
||||
|
||||
//Disco register
|
||||
for(u32 i = 0; i < 256; i++)
|
||||
*(vu32 *)0x10400584 = 0x10101 * i;
|
||||
|
||||
*(vu32 *)0x10202204 = 0x00000000; //unset LCD fill
|
||||
*(vu32 *)0x10202A04 = 0x00000000;
|
||||
}
|
||||
|
||||
static void setupFramebuffers(struct fb *fbs)
|
||||
{
|
||||
*(vu32 *)0x10202204 = 0x01000000; //set LCD fill black to hide potential garbage -- NFIRM does it before firmlaunching
|
||||
*(vu32 *)0x10202A04 = 0x01000000;
|
||||
|
||||
*(vu32 *)0x10400468 = (u32)fbs[0].top_left;
|
||||
*(vu32 *)0x1040046c = (u32)fbs[1].top_left;
|
||||
*(vu32 *)0x10400494 = (u32)fbs[0].top_right;
|
||||
*(vu32 *)0x10400498 = (u32)fbs[1].top_right;
|
||||
*(vu32 *)0x10400568 = (u32)fbs[0].bottom;
|
||||
*(vu32 *)0x1040056c = (u32)fbs[1].bottom;
|
||||
|
||||
//Set framebuffer format, framebuffer select and stride
|
||||
*(vu32 *)0x10400470 = 0x80341;
|
||||
*(vu32 *)0x10400478 = 0;
|
||||
*(vu32 *)0x10400490 = 0x2D0;
|
||||
*(vu32 *)0x10400570 = 0x80301;
|
||||
*(vu32 *)0x10400578 = 0;
|
||||
*(vu32 *)0x10400590 = 0x2D0;
|
||||
|
||||
*(vu32 *)0x10202204 = 0x00000000; //unset LCD fill
|
||||
*(vu32 *)0x10202A04 = 0x00000000;
|
||||
}
|
||||
|
||||
static void clearScreens(struct fb *fb)
|
||||
{
|
||||
//Setting up two simultaneous memory fills using the GPU
|
||||
|
||||
vu32 *REGs_PSC0 = (vu32 *)0x10400010,
|
||||
*REGs_PSC1 = (vu32 *)0x10400020;
|
||||
|
||||
REGs_PSC0[0] = (u32)fb->top_left >> 3; //Start address
|
||||
REGs_PSC0[1] = (u32)(fb->top_left + SCREEN_TOP_FBSIZE) >> 3; //End address
|
||||
REGs_PSC0[2] = 0; //Fill value
|
||||
REGs_PSC0[3] = (2 << 8) | 1; //32-bit pattern; start
|
||||
|
||||
REGs_PSC1[0] = (u32)fb->bottom >> 3; //Start address
|
||||
REGs_PSC1[1] = (u32)(fb->bottom + SCREEN_BOTTOM_FBSIZE) >> 3; //End address
|
||||
REGs_PSC1[2] = 0; //Fill value
|
||||
REGs_PSC1[3] = (2 << 8) | 1; //32-bit pattern; start
|
||||
|
||||
while(!((REGs_PSC0[3] & 2) && (REGs_PSC1[3] & 2)));
|
||||
}
|
||||
|
||||
static void swapFramebuffers(bool isAlternate)
|
||||
{
|
||||
u32 isAlternateTmp = isAlternate ? 1 : 0;
|
||||
*(vu32 *)0x10400478 = (*(vu32 *)0x10400478 & 0xFFFFFFFE) | isAlternateTmp;
|
||||
*(vu32 *)0x10400578 = (*(vu32 *)0x10400478 & 0xFFFFFFFE) | isAlternateTmp;
|
||||
}
|
||||
|
||||
static void updateBrightness(u32 brightnessLevel)
|
||||
{
|
||||
//Change brightness
|
||||
*(vu32 *)0x10202240 = brightnessLevel;
|
||||
*(vu32 *)0x10202A40 = brightnessLevel;
|
||||
}
|
||||
|
||||
static void deinitScreens(void)
|
||||
{
|
||||
//Shutdown LCDs
|
||||
*(vu32 *)0x10202A44 = 0;
|
||||
*(vu32 *)0x10202244 = 0;
|
||||
*(vu32 *)0x10202014 = 0;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
operation = ARM11_READY;
|
||||
|
||||
while(true)
|
||||
{
|
||||
switch(operation)
|
||||
{
|
||||
case ARM11_READY:
|
||||
continue;
|
||||
case INIT_SCREENS:
|
||||
initScreens(*(vu32 *)ARM11_PARAMETERS_ADDRESS, (struct fb *)(ARM11_PARAMETERS_ADDRESS + 4));
|
||||
break;
|
||||
case SETUP_FRAMEBUFFERS:
|
||||
setupFramebuffers((struct fb *)ARM11_PARAMETERS_ADDRESS);
|
||||
break;
|
||||
case CLEAR_SCREENS:
|
||||
clearScreens((struct fb *)ARM11_PARAMETERS_ADDRESS);
|
||||
break;
|
||||
case SWAP_FRAMEBUFFERS:
|
||||
swapFramebuffers(*(volatile bool *)ARM11_PARAMETERS_ADDRESS);
|
||||
break;
|
||||
case UPDATE_BRIGHTNESS:
|
||||
updateBrightness(*(vu32 *)ARM11_PARAMETERS_ADDRESS);
|
||||
break;
|
||||
case DEINIT_SCREENS:
|
||||
deinitScreens();
|
||||
break;
|
||||
case PREPARE_ARM11_FOR_FIRMLAUNCH:
|
||||
memcpy((void *)0x1FFFFC00, (void *)prepareForFirmlaunch, prepareForFirmlaunchSize);
|
||||
*(vu32 *)0x1FFFFFFC = 0;
|
||||
((void (*)(u32, volatile Arm11Operation *))0x1FFFFC00)(ARM11_READY, &operation);
|
||||
}
|
||||
|
||||
operation = ARM11_READY;
|
||||
}
|
||||
}
|
||||
56
arm11/source/memory.c
Normal file
56
arm11/source/memory.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* memcpy adapted from https://github.com/mid-kid/CakesForeveryWan/blob/557a8e8605ab3ee173af6497486e8f22c261d0e2/source/memfuncs.c
|
||||
*/
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
void memcpy(void *dest, const void *src, u32 size)
|
||||
{
|
||||
u8 *destc = (u8 *)dest;
|
||||
const u8 *srcc = (const u8 *)src;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
destc[i] = srcc[i];
|
||||
}
|
||||
|
||||
void memset(void *dest, u32 filler, u32 size)
|
||||
{
|
||||
u8 *destc = (u8 *)dest;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
destc[i] = (u8)filler;
|
||||
}
|
||||
|
||||
void memset32(void *dest, u32 filler, u32 size)
|
||||
{
|
||||
u32 *dest32 = (u32 *)dest;
|
||||
|
||||
for(u32 i = 0; i < size / 4; i++)
|
||||
dest32[i] = filler;
|
||||
}
|
||||
37
arm11/source/memory.h
Normal file
37
arm11/source/memory.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* memcpy adapted from https://github.com/mid-kid/CakesForeveryWan/blob/557a8e8605ab3ee173af6497486e8f22c261d0e2/source/memfuncs.c
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void memcpy(void *dest, const void *src, u32 size);
|
||||
void memset(void *dest, u32 value, u32 size) __attribute__((used));
|
||||
void memset32(void *dest, u32 filler, u32 size);
|
||||
86
arm11/source/start.s
Normal file
86
arm11/source/start.s
Normal file
@@ -0,0 +1,86 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
@
|
||||
@ 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 <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.section .text.start, "ax", %progbits
|
||||
.align 4
|
||||
.global _start
|
||||
.type _start, %function
|
||||
_start:
|
||||
b start
|
||||
|
||||
.global operation
|
||||
operation:
|
||||
.word 0
|
||||
|
||||
start:
|
||||
@ Disable interrupts and switch to supervisor mode
|
||||
cpsid aif, #0x13
|
||||
|
||||
@ Set the control register to reset default: everything disabled
|
||||
ldr r0, =0x54078
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
@ Set the auxiliary control register to reset default.
|
||||
@ Enables instruction folding, static branch prediction,
|
||||
@ dynamic branch prediction, and return stack.
|
||||
mov r0, #0xF
|
||||
mcr p15, 0, r0, c1, c0, 1
|
||||
|
||||
@ Invalidate both caches, flush the prefetch buffer then DSB
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c5, 4
|
||||
mcr p15, 0, r0, c7, c7, 0
|
||||
mcr p15, 0, r0, c7, c10, 4
|
||||
|
||||
ldr sp, =__stack_top__
|
||||
mov fp, #0
|
||||
|
||||
@ Clear BSS
|
||||
ldr r0, =__bss_start__
|
||||
mov r1, #0
|
||||
ldr r2, =__bss_end__
|
||||
sub r2, r0
|
||||
bl memset
|
||||
|
||||
@ Call the init array
|
||||
bl __libc_init_array
|
||||
|
||||
b main
|
||||
|
||||
.global prepareForFirmlaunch
|
||||
.type prepareForFirmlaunch, %function
|
||||
prepareForFirmlaunch:
|
||||
str r0, [r1] @ tell Arm9 we're done
|
||||
mov r0, #0x20000000
|
||||
|
||||
_wait_for_core0_entrypoint_loop:
|
||||
ldr r1, [r0, #-4] @ check if core0's entrypoint is 0
|
||||
cmp r1, #0
|
||||
beq _wait_for_core0_entrypoint_loop
|
||||
|
||||
bx r1 @ jump to core0's entrypoint
|
||||
prepareForFirmlaunchEnd:
|
||||
|
||||
.global prepareForFirmlaunchSize
|
||||
prepareForFirmlaunchSize: .word prepareForFirmlaunchEnd - prepareForFirmlaunch
|
||||
65
arm11/source/types.h
Normal file
65
arm11/source/types.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
//Common data types
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
typedef volatile u8 vu8;
|
||||
typedef volatile u16 vu16;
|
||||
typedef volatile u32 vu32;
|
||||
typedef volatile u64 vu64;
|
||||
|
||||
#define SCREEN_TOP_WIDTH 400
|
||||
#define SCREEN_BOTTOM_WIDTH 320
|
||||
#define SCREEN_HEIGHT 240
|
||||
#define SCREEN_TOP_FBSIZE (3 * SCREEN_TOP_WIDTH * SCREEN_HEIGHT)
|
||||
#define SCREEN_BOTTOM_FBSIZE (3 * SCREEN_BOTTOM_WIDTH * SCREEN_HEIGHT)
|
||||
#define ARM11_PARAMETERS_ADDRESS 0x1FFFF000
|
||||
|
||||
struct fb {
|
||||
u8 *top_left;
|
||||
u8 *top_right;
|
||||
u8 *bottom;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INIT_SCREENS = 0,
|
||||
SETUP_FRAMEBUFFERS,
|
||||
CLEAR_SCREENS,
|
||||
SWAP_FRAMEBUFFERS,
|
||||
UPDATE_BRIGHTNESS,
|
||||
DEINIT_SCREENS,
|
||||
PREPARE_ARM11_FOR_FIRMLAUNCH,
|
||||
ARM11_READY,
|
||||
} Arm11Operation;
|
||||
176
arm9/Makefile
Normal file
176
arm9/Makefile
Normal file
@@ -0,0 +1,176 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITARM)/base_rules
|
||||
|
||||
export REVISION := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
||||
export VERSION_MAJOR := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f1 -d.)
|
||||
export VERSION_MINOR := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f2 -d.)
|
||||
export VERSION_BUILD := $(shell git describe --tags --match v[0-9]* | cut -c2- | cut -f1 -d- | cut -f3 -d.)
|
||||
export COMMIT := $(shell git rev-parse --short=8 HEAD)
|
||||
export IS_RELEASE := 0
|
||||
|
||||
ifeq ($(strip $(REVISION)),)
|
||||
export REVISION := v0.0.0-0
|
||||
export VERSION_MAJOR := 0
|
||||
export VERSION_MINOR := 0
|
||||
export VERSION_BUILD := 0
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(COMMIT)),)
|
||||
export COMMIT := 0
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(VERSION_BUILD)),)
|
||||
export VERSION_BUILD := 0
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(shell git describe --tags --match v[0-9]* | grep -)),)
|
||||
export IS_RELEASE := 1
|
||||
endif
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
APP_TITLE := Luma3DS
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source source/fatfs source/fatfs/sdmmc
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -marm -march=armv5te -mtune=arm946e-s
|
||||
DEFINES := -DARM9 -D_3DS
|
||||
|
||||
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
||||
-Wno-main $(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE)
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS :=
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
export APP_TITLE := $(notdir $(TOPDIR)/..)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).elf
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
%.elf: $(OFILES)
|
||||
@echo linking $(notdir $@)
|
||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
||||
@$(NM) -CSn $@ > $(notdir $*.lst)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
memory.o strings.o: CFLAGS += -O3
|
||||
config.o: CFLAGS += -DCONFIG_TITLE="\"$(APP_TITLE) $(REVISION) configuration\""
|
||||
patches.o: CFLAGS += -DVERSION_MAJOR="$(VERSION_MAJOR)" -DVERSION_MINOR="$(VERSION_MINOR)"\
|
||||
-DVERSION_BUILD="$(VERSION_BUILD)" -DISRELEASE="$(IS_RELEASE)" -DCOMMIT_HASH="0x$(COMMIT)"
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
209
arm9/linker.ld
Normal file
209
arm9/linker.ld
Normal file
@@ -0,0 +1,209 @@
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(_start)
|
||||
|
||||
PHDRS
|
||||
{
|
||||
crt0 PT_LOAD;
|
||||
itcm PT_LOAD;
|
||||
main PT_LOAD;
|
||||
}
|
||||
|
||||
/* Mostly copied from https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/3dsx.ld */
|
||||
MEMORY
|
||||
{
|
||||
main : ORIGIN = 0x08006000, LENGTH = 0x080F0000 - 0x08006000
|
||||
itcm : ORIGIN = 0x01FF8000, LENGTH = 0x01FFB800 - 0x01FF8000 /* Unused ITCM slice. */
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
PROVIDE(__start__ = 0x08006000);
|
||||
PROVIDE(__stack_top__ = 0x08100000);
|
||||
PROVIDE(__stack_bottom__ = 0x080F0000);
|
||||
|
||||
PROVIDE(__itcm_stack_top__ = 0x01FFB800);
|
||||
PROVIDE(__itcm_stack_bottom__ = 0x01FFA800);
|
||||
|
||||
. = __start__;
|
||||
|
||||
.crt0 :
|
||||
{
|
||||
KEEP( *(.text.start) )
|
||||
KEEP( *(.init) )
|
||||
. = ALIGN(32);
|
||||
} >main :crt0
|
||||
|
||||
.itcm_loadable :
|
||||
{
|
||||
PROVIDE (__itcm_start__ = ABSOLUTE(.));
|
||||
PROVIDE (__itcm_lma__ = LOADADDR(.itcm_loadable));
|
||||
|
||||
KEEP(*(.arm9_exception_handlers.text))
|
||||
*(.arm9_exception_handlers.text*)
|
||||
KEEP(*(.chainloader.text.start))
|
||||
|
||||
chainloader.o(.text*)
|
||||
i2c.o(.text*)
|
||||
arm9_exception_handlers.o(.text*)
|
||||
|
||||
*(.arm9_exception_handlers.rodata*)
|
||||
chainloader.o(.rodata*)
|
||||
i2c.o(.rodata*)
|
||||
arm9_exception_handlers.o(.rodata*)
|
||||
|
||||
*(.arm9_exception_handlers.data*)
|
||||
chainloader.o(.data*)
|
||||
i2c.o(.data*)
|
||||
arm9_exception_handlers.o(.data*)
|
||||
. = ALIGN(32);
|
||||
} >itcm AT>main :itcm
|
||||
|
||||
.itcm_bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(32);
|
||||
PROVIDE (__itcm_bss_start__ = ABSOLUTE(.));
|
||||
|
||||
*(.arm9_exception_handlers.bss*)
|
||||
chainloader.o(.bss* COMMON)
|
||||
i2c.o(.bss* COMMON)
|
||||
arm9_exception_handlers.o(.bss* COMMON)
|
||||
. = ALIGN(32);
|
||||
PROVIDE (__itcm_end__ = ABSOLUTE(.));
|
||||
} >itcm :NONE
|
||||
|
||||
.text :
|
||||
{
|
||||
/* .text */
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
*(.stub)
|
||||
*(.gnu.warning)
|
||||
*(.gnu.linkonce.t*)
|
||||
|
||||
/* .fini */
|
||||
KEEP( *(.fini) )
|
||||
. = ALIGN(8);
|
||||
} >main :main
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.roda)
|
||||
*(.rodata.*)
|
||||
*all.rodata*(*)
|
||||
*(.gnu.linkonce.r*)
|
||||
SORT(CONSTRUCTORS)
|
||||
. = ALIGN(8);
|
||||
} >main
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE (__preinit_array_end = .);
|
||||
} >main
|
||||
|
||||
.init_array ALIGN(4) :
|
||||
{
|
||||
PROVIDE (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE (__init_array_end = .);
|
||||
} >main
|
||||
|
||||
.fini_array ALIGN(4) :
|
||||
{
|
||||
PROVIDE (__fini_array_start = .);
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE (__fini_array_end = .);
|
||||
} >main
|
||||
|
||||
.ctors ALIGN(4) :
|
||||
{
|
||||
KEEP (*crtbegin.o(.ctors)) /* MUST be first -- GCC requires it */
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
||||
} >main
|
||||
|
||||
.dtors ALIGN(4) :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
. = ALIGN(4); /* REQUIRED. LD is flaky without it. */
|
||||
} >main
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) __exidx_start = ABSOLUTE(.);} >main
|
||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) __exidx_end = ABSOLUTE(.);} >main
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
KEEP (*(.large_patch*))
|
||||
*(.gnu.linkonce.d*)
|
||||
CONSTRUCTORS
|
||||
. = ALIGN(32);
|
||||
} >main
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(32);
|
||||
PROVIDE (__bss_start__ = ABSOLUTE(.));
|
||||
*(.dynbss)
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.gnu.linkonce.b*)
|
||||
*(COMMON)
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__bss_end__ = ABSOLUTE(.));
|
||||
} >main :NONE
|
||||
__end__ = ABSOLUTE(.) ;
|
||||
|
||||
/* ==================
|
||||
==== Metadata ====
|
||||
================== */
|
||||
|
||||
/* Discard sections that difficult post-processing */
|
||||
/DISCARD/ : { *(.group .comment .note) }
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
|
||||
/* DWARF debug sections.
|
||||
Symbols in the DWARF debugging sections are relative to the beginning
|
||||
of the section so we begin them at 0. */
|
||||
|
||||
/* DWARF 1 */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
|
||||
/* GNU DWARF 1 extensions */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
|
||||
/* DWARF 1.1 and DWARF 2 */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
|
||||
/* DWARF 2 */
|
||||
.debug_info 0 : { *(.debug_info) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
}
|
||||
7
arm9/linker.specs
Normal file
7
arm9/linker.specs
Normal file
@@ -0,0 +1,7 @@
|
||||
%rename link old_link
|
||||
|
||||
*link:
|
||||
%(old_link) -T %:getenv(TOPDIR /linker.ld) --nmagic --gc-sections
|
||||
|
||||
*startfile:
|
||||
crti%O%s crtbegin%O%s
|
||||
167
arm9/source/3dsheaders.h
Normal file
167
arm9/source/3dsheaders.h
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Adapted from 3DBrew and https://github.com/mid-kid/CakesForeveryWan/blob/master/source/headers.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 address;
|
||||
u32 phyRegionSize;
|
||||
u32 size;
|
||||
} CodeSetInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 saveDataSize[2];
|
||||
u32 jumpID[2];
|
||||
u8 reserved[0x30];
|
||||
} SystemInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char appTitle[8];
|
||||
u8 reserved1[5];
|
||||
u8 flag;
|
||||
u8 remasterVersion[2];
|
||||
CodeSetInfo textCodeSet;
|
||||
u32 stackSize;
|
||||
CodeSetInfo roCodeSet;
|
||||
u8 reserved2[4];
|
||||
CodeSetInfo dataCodeSet;
|
||||
u32 bssSize;
|
||||
char depends[0x180];
|
||||
SystemInfo systemInfo;
|
||||
} SystemControlInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SystemControlInfo systemControlInfo;
|
||||
u8 aci[0x200];
|
||||
u8 accessDescSig[0x100];
|
||||
u8 ncchPubKey[0x100];
|
||||
u8 aciLim[0x200];
|
||||
} ExHeader;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 sig[0x100]; //RSA-2048 signature of the NCCH header, using SHA-256
|
||||
char magic[4]; //NCCH
|
||||
u32 contentSize; //Media unit
|
||||
u8 partitionId[8];
|
||||
u8 makerCode[2];
|
||||
u16 version;
|
||||
u8 reserved1[4];
|
||||
u8 programID[8];
|
||||
u8 reserved2[0x10];
|
||||
u8 logoHash[0x20]; //Logo Region SHA-256 hash
|
||||
char productCode[0x10];
|
||||
u8 exHeaderHash[0x20]; //Extended header SHA-256 hash
|
||||
u32 exHeaderSize; //Extended header size
|
||||
u32 reserved3;
|
||||
u8 flags[8];
|
||||
u32 plainOffset; //Media unit
|
||||
u32 plainSize; //Media unit
|
||||
u32 logoOffset; //Media unit
|
||||
u32 logoSize; //Media unit
|
||||
u32 exeFsOffset; //Media unit
|
||||
u32 exeFsSize; //Media unit
|
||||
u32 exeFsHashSize; //Media unit
|
||||
u32 reserved4;
|
||||
u32 romFsOffset; //Media unit
|
||||
u32 romFsSize; //Media unit
|
||||
u32 romFsHashSize; //Media unit
|
||||
u32 reserved5;
|
||||
u8 exeFsHash[0x20]; //ExeFS superblock SHA-256 hash
|
||||
u8 romFsHash[0x20]; //RomFS superblock SHA-256 hash
|
||||
} Ncch;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Ncch ncch;
|
||||
ExHeader exHeader;
|
||||
} Cxi;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char sigIssuer[0x40];
|
||||
u8 eccPubKey[0x3C];
|
||||
u8 version;
|
||||
u8 caCrlVersion;
|
||||
u8 signerCrlVersion;
|
||||
u8 titleKey[0x10];
|
||||
u8 reserved1;
|
||||
u8 ticketId[8];
|
||||
u8 consoleId[4];
|
||||
u8 titleId[8];
|
||||
u8 reserved2[2];
|
||||
u16 ticketTitleVersion;
|
||||
u8 reserved3[8];
|
||||
u8 licenseType;
|
||||
u8 ticketCommonKeyYIndex; //Ticket common keyY index, usually 0x1 for retail system titles.
|
||||
u8 reserved4[0x2A];
|
||||
u8 unk[4]; //eShop Account ID?
|
||||
u8 reserved5;
|
||||
u8 audit;
|
||||
u8 reserved6[0x42];
|
||||
u8 limits[0x40];
|
||||
u8 contentIndex[0xAC];
|
||||
} Ticket;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 offset;
|
||||
u8 *address;
|
||||
u32 size;
|
||||
u32 procType;
|
||||
u8 hash[0x20];
|
||||
} FirmSection;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char magic[4];
|
||||
u32 reserved1;
|
||||
u8 *arm11Entry;
|
||||
u8 *arm9Entry;
|
||||
u8 reserved2[0x30];
|
||||
FirmSection section[4];
|
||||
} Firm;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 keyX[0x10];
|
||||
u8 keyY[0x10];
|
||||
u8 ctr[0x10];
|
||||
char size[8];
|
||||
u8 reserved[8];
|
||||
u8 ctlBlock[0x10];
|
||||
char magic[4];
|
||||
u8 reserved2[0xC];
|
||||
u8 slot0x16keyX[0x10];
|
||||
} Arm9Bin;
|
||||
28
arm9/source/alignedseqmemcpy.h
Normal file
28
arm9/source/alignedseqmemcpy.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
#include "types.h"
|
||||
|
||||
void *alignedseqmemcpy(void *dst, const void *src, u32 len);
|
||||
65
arm9/source/alignedseqmemcpy.s
Normal file
65
arm9/source/alignedseqmemcpy.s
Normal file
@@ -0,0 +1,65 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
@
|
||||
@ 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 <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.section .text.alignedseqmemcpy, "ax", %progbits
|
||||
.arm
|
||||
@ Align on cache line boundaries & make sure the loops don't cross them.
|
||||
.align 5
|
||||
.global alignedseqmemcpy
|
||||
.type alignedseqmemcpy, %function
|
||||
alignedseqmemcpy:
|
||||
@ src=r1 and dst=r0 are expected to be 4-byte-aligned
|
||||
push {r4-r10, lr}
|
||||
|
||||
lsrs r12, r2, #5
|
||||
sub r2, r2, r12, lsl #5
|
||||
beq 2f
|
||||
|
||||
1:
|
||||
ldmia r1!, {r3-r10}
|
||||
stmia r0!, {r3-r10}
|
||||
subs r12, #1
|
||||
bne 1b
|
||||
|
||||
2:
|
||||
lsrs r12, r2, #2
|
||||
sub r2, r2, r12, lsl #2
|
||||
beq 4f
|
||||
|
||||
3:
|
||||
ldr r3, [r1], #4
|
||||
str r3, [r0], #4
|
||||
subs r12, #1
|
||||
bne 3b
|
||||
|
||||
4:
|
||||
tst r2, #2
|
||||
ldrneh r3, [r1], #2
|
||||
strneh r3, [r0], #2
|
||||
|
||||
tst r2, #1
|
||||
ldrneb r3, [r1], #1
|
||||
strneb r3, [r0], #1
|
||||
|
||||
pop {r4-r10, pc}
|
||||
83
arm9/source/arm9_exception_handlers.c
Normal file
83
arm9/source/arm9_exception_handlers.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "arm9_exception_handlers.h"
|
||||
#include "i2c.h"
|
||||
#include "screen.h"
|
||||
|
||||
#define FINAL_BUFFER 0x25000000
|
||||
|
||||
#define REG_DUMP_SIZE 4 * 17
|
||||
#define CODE_DUMP_SIZE 48
|
||||
|
||||
void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 type)
|
||||
{
|
||||
ExceptionDumpHeader dumpHeader;
|
||||
|
||||
u8 codeDump[CODE_DUMP_SIZE];
|
||||
|
||||
dumpHeader.magic[0] = 0xDEADC0DE;
|
||||
dumpHeader.magic[1] = 0xDEADCAFE;
|
||||
dumpHeader.versionMajor = 1;
|
||||
dumpHeader.versionMinor = 2;
|
||||
|
||||
dumpHeader.processor = 9;
|
||||
dumpHeader.core = 0;
|
||||
dumpHeader.type = type;
|
||||
|
||||
dumpHeader.registerDumpSize = REG_DUMP_SIZE;
|
||||
dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
|
||||
dumpHeader.additionalDataSize = 0;
|
||||
|
||||
u32 cpsr = registerDump[16];
|
||||
u32 pc = registerDump[15] - (type < 3 ? (((cpsr & 0x20) != 0 && type == 1) ? 2 : 4) : 8);
|
||||
|
||||
registerDump[15] = pc;
|
||||
|
||||
//Dump code
|
||||
u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //wouldn't work well on 32-bit Thumb instructions, but it isn't much of a problem
|
||||
dumpHeader.codeDumpSize = ((u32)instr & (((cpsr & 0x20) != 0) ? 1 : 3)) != 0 ? 0 : safecpy(codeDump, instr, dumpHeader.codeDumpSize);
|
||||
|
||||
//Copy register dump and code dump
|
||||
u8 *final = (u8 *)(FINAL_BUFFER + sizeof(ExceptionDumpHeader));
|
||||
final += safecpy(final, registerDump, dumpHeader.registerDumpSize);
|
||||
final += safecpy(final, codeDump, dumpHeader.codeDumpSize);
|
||||
|
||||
//Dump stack in place
|
||||
dumpHeader.stackDumpSize = safecpy(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF));
|
||||
|
||||
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
|
||||
|
||||
//Copy header (actually optimized by the compiler)
|
||||
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
||||
|
||||
if(ARESCREENSINITIALIZED) I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0); //Shutdown LCD
|
||||
|
||||
((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed
|
||||
|
||||
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
||||
while(true);
|
||||
}
|
||||
32
arm9/source/arm9_exception_handlers.h
Normal file
32
arm9/source/arm9_exception_handlers.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
|
||||
extern const u32 arm9ExceptionHandlerAddressTable[6];
|
||||
extern u32 arm9ExceptionHandlerSvcBreakAddress;
|
||||
|
||||
u32 safecpy(void *dst, const void *src, u32 len);
|
||||
168
arm9/source/arm9_exception_handlers_asm.s
Normal file
168
arm9/source/arm9_exception_handlers_asm.s
Normal file
@@ -0,0 +1,168 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
@
|
||||
@ 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 <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.macro GEN_USUAL_HANDLER name, index
|
||||
\name\()Handler:
|
||||
ldr sp, =_regs
|
||||
stmia sp, {r0-r7}
|
||||
|
||||
mov r0, #\index
|
||||
b _arm9ExceptionHandlerCommon
|
||||
.endm
|
||||
|
||||
.section .arm9_exception_handlers.text, "ax", %progbits
|
||||
.arm
|
||||
.align 4
|
||||
|
||||
.global _arm9ExceptionHandlerCommon
|
||||
.type _arm9ExceptionHandlerCommon, %function
|
||||
_arm9ExceptionHandlerCommon:
|
||||
mov r1, r0
|
||||
mov r0, sp
|
||||
mrs r2, spsr
|
||||
mrs r3, cpsr
|
||||
add r6, r0, #(8 * 4)
|
||||
|
||||
orr r3, #0xc0 @ mask interrupts
|
||||
msr cpsr_cx, r3
|
||||
|
||||
ands r4, r2, #0xf @ get the mode that triggered the exception
|
||||
moveq r4, #0xf @ usr => sys
|
||||
bic r5, r3, #0xf
|
||||
orr r5, r4
|
||||
msr cpsr_c, r5 @ change processor mode
|
||||
stmia r6!, {r8-lr}
|
||||
msr cpsr_c, r3 @ restore processor mode
|
||||
|
||||
str lr, [r6], #4
|
||||
str r2, [r6]
|
||||
|
||||
msr cpsr_cxsf, #0xdf @ finally, switch to system mode, mask interrupts and clear flags (in case of double faults)
|
||||
ldr sp, =0x02000000
|
||||
b arm9ExceptionHandlerMain
|
||||
|
||||
|
||||
.global FIQHandler
|
||||
.type FIQHandler, %function
|
||||
GEN_USUAL_HANDLER FIQ, 0
|
||||
|
||||
.global undefinedInstructionHandler
|
||||
.type undefinedInstructionHandler, %function
|
||||
GEN_USUAL_HANDLER undefinedInstruction, 1
|
||||
|
||||
.global prefetchAbortHandler
|
||||
.type prefetchAbortHandler, %function
|
||||
prefetchAbortHandler:
|
||||
msr cpsr_cx, #0xd7 @ mask interrupts (abort mode)
|
||||
mrs sp, spsr
|
||||
and sp, #0x3f
|
||||
cmp sp, #0x13
|
||||
bne _prefetchAbortNormalHandler
|
||||
|
||||
ldr sp, =arm9ExceptionHandlerSvcBreakAddress
|
||||
ldr sp, [sp]
|
||||
cmp sp, #0
|
||||
beq _prefetchAbortNormalHandler
|
||||
add sp, #(1*4 + 4)
|
||||
cmp lr, sp
|
||||
bne _prefetchAbortNormalHandler
|
||||
|
||||
mov sp, r8
|
||||
pop {r8-r11}
|
||||
ldr lr, [sp, #8]!
|
||||
ldr sp, [sp, #4]
|
||||
msr spsr_cxsf, sp
|
||||
tst sp, #0x20
|
||||
addne lr, #2 @ adjust address for later
|
||||
|
||||
GEN_USUAL_HANDLER _prefetchAbortNormal, 2
|
||||
|
||||
.global dataAbortHandler
|
||||
.type dataAbortHandler, %function
|
||||
dataAbortHandler:
|
||||
msr cpsr_cx, #0xd7 @ mask interrupts (abort mode)
|
||||
mrs sp, spsr
|
||||
and sp, #0x3f
|
||||
cmp sp, #0x1f
|
||||
bne _dataAbortNormalHandler
|
||||
|
||||
sub lr, #8
|
||||
adr sp, safecpy
|
||||
cmp lr, sp
|
||||
blo _j_dataAbortNormalHandler
|
||||
adr sp, _safecpy_end
|
||||
cmp lr, sp
|
||||
bhs _j_dataAbortNormalHandler
|
||||
|
||||
msr spsr_f, #(1 << 30)
|
||||
mov r12, #0
|
||||
adds pc, lr, #4
|
||||
|
||||
_j_dataAbortNormalHandler:
|
||||
add lr, #8
|
||||
|
||||
GEN_USUAL_HANDLER _dataAbortNormal, 3
|
||||
|
||||
|
||||
.global safecpy
|
||||
.type safecpy, %function
|
||||
safecpy:
|
||||
push {r4, lr}
|
||||
mov r3, #0
|
||||
movs r12, #1
|
||||
|
||||
_safecpy_loop:
|
||||
ldrb r4, [r1, r3]
|
||||
cmp r12, #0
|
||||
beq _safecpy_loop_end
|
||||
strb r4, [r0, r3]
|
||||
add r3, #1
|
||||
cmp r3, r2
|
||||
blo _safecpy_loop
|
||||
|
||||
_safecpy_loop_end:
|
||||
mov r0, r3
|
||||
pop {r4, pc}
|
||||
|
||||
_safecpy_end:
|
||||
|
||||
.section .arm9_exception_handlers.rodata, "a", %progbits
|
||||
.align 4
|
||||
.global arm9ExceptionHandlerAddressTable
|
||||
arm9ExceptionHandlerAddressTable:
|
||||
.word 0 @ IRQ
|
||||
.word FIQHandler @ FIQ
|
||||
.word 0 @ SVC
|
||||
.word undefinedInstructionHandler @ Undefined instruction
|
||||
.word prefetchAbortHandler @ Prefetch abort
|
||||
.word dataAbortHandler @ Data abort
|
||||
|
||||
.section .arm9_exception_handlers.bss, "aw", %nobits
|
||||
.align 4
|
||||
|
||||
.global arm9ExceptionHandlerSvcBreakAddress
|
||||
arm9ExceptionHandlerSvcBreakAddress:
|
||||
.skip 4
|
||||
|
||||
_regs: .skip (4 * 17)
|
||||
52
arm9/source/buttons.h
Normal file
52
arm9/source/buttons.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF)
|
||||
|
||||
#define BUTTON_R1 (1 << 8)
|
||||
#define BUTTON_L1 (1 << 9)
|
||||
#define BUTTON_A (1 << 0)
|
||||
#define BUTTON_B (1 << 1)
|
||||
#define BUTTON_X (1 << 10)
|
||||
#define BUTTON_Y (1 << 11)
|
||||
#define BUTTON_SELECT (1 << 2)
|
||||
#define BUTTON_START (1 << 3)
|
||||
#define BUTTON_RIGHT (1 << 4)
|
||||
#define BUTTON_LEFT (1 << 5)
|
||||
#define BUTTON_UP (1 << 6)
|
||||
#define BUTTON_DOWN (1 << 7)
|
||||
|
||||
#define DPAD_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN)
|
||||
#define SAFE_MODE (BUTTON_R1 | BUTTON_L1 | BUTTON_A | BUTTON_UP)
|
||||
#define SINGLE_PAYLOAD_BUTTONS (BUTTON_B | BUTTON_X | BUTTON_Y)
|
||||
#define L_PAYLOAD_BUTTONS (BUTTON_R1 | BUTTON_A | BUTTON_START | BUTTON_SELECT)
|
||||
#define MENU_BUTTONS (DPAD_BUTTONS | BUTTON_A | BUTTON_START)
|
||||
#define PIN_BUTTONS (BUTTON_A | BUTTON_B | BUTTON_X | BUTTON_Y | DPAD_BUTTONS | BUTTON_START | BUTTON_SELECT)
|
||||
#define NTRBOOT_BUTTONS (BUTTON_START | BUTTON_SELECT | BUTTON_X)
|
||||
43
arm9/source/cache.h
Normal file
43
arm9/source/cache.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/***
|
||||
The following functions flush the data cache, then waits for all memory transfers to be finished.
|
||||
The data cache and/or the instruction cache MUST be flushed before doing one of the following:
|
||||
- rebooting
|
||||
- powering down
|
||||
- setting the Arm11 entrypoint to execute a function
|
||||
- jumping to a payload
|
||||
***/
|
||||
|
||||
void flushEntireDCache(void); //actually: "clean and flush"
|
||||
void flushDCacheRange(void *startAddress, u32 size);
|
||||
void flushEntireICache(void);
|
||||
void flushICacheRange(void *startAddress, u32 size);
|
||||
93
arm9/source/cache.s
Normal file
93
arm9/source/cache.s
Normal file
@@ -0,0 +1,93 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
@
|
||||
@ 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 <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.section .text.cache, "ax", %progbits
|
||||
.arm
|
||||
.align 4
|
||||
|
||||
.global flushEntireDCache
|
||||
.type flushEntireDCache, %function
|
||||
flushEntireDCache:
|
||||
@ Adapted from http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0155a/ch03s03s05.html,
|
||||
@ and https://github.com/gemarcano/libctr9_io/blob/master/src/ctr_system_ARM.c#L39 as well
|
||||
@ Note: Arm's example is actually for a 8KB DCache (which is what the 3DS has)
|
||||
|
||||
@ Implemented in bootROM at address 0xffff0830
|
||||
mov r1, #0 @ segment counter
|
||||
outer_loop:
|
||||
mov r0, #0 @ line counter
|
||||
|
||||
inner_loop:
|
||||
orr r2, r1, r0 @ generate segment and line address
|
||||
mcr p15, 0, r2, c7, c14, 2 @ clean and flush the line
|
||||
add r0, #0x20 @ increment to next line
|
||||
cmp r0, #0x400
|
||||
bne inner_loop
|
||||
|
||||
add r1, #0x40000000
|
||||
cmp r1, #0
|
||||
bne outer_loop
|
||||
|
||||
mcr p15, 0, r1, c7, c10, 4 @ drain write buffer
|
||||
bx lr
|
||||
|
||||
.global flushDCacheRange
|
||||
.type flushDCacheRange, %function
|
||||
flushDCacheRange:
|
||||
@ Implemented in bootROM at address 0xffff08a0
|
||||
add r1, r0, r1 @ end address
|
||||
bic r0, #0x1f @ align source address to cache line size (32 bytes)
|
||||
|
||||
flush_dcache_range_loop:
|
||||
mcr p15, 0, r0, c7, c14, 1 @ clean and flush the line corresponding to the address r0 is holding
|
||||
add r0, #0x20
|
||||
cmp r0, r1
|
||||
blo flush_dcache_range_loop
|
||||
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
|
||||
bx lr
|
||||
|
||||
.global flushEntireICache
|
||||
.type flushEntireICache, %function
|
||||
flushEntireICache:
|
||||
@ Implemented in bootROM at address 0xffff0ab4
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c7, c5, 0
|
||||
bx lr
|
||||
|
||||
.global flushICacheRange
|
||||
.type flushICacheRange, %function
|
||||
flushICacheRange:
|
||||
@ Implemented in bootROM at address 0xffff0ac0
|
||||
add r1, r0, r1 @ end address
|
||||
bic r0, #0x1f @ align source address to cache line size (32 bytes)
|
||||
|
||||
flush_icache_range_loop:
|
||||
mcr p15, 0, r0, c7, c5, 1 @ flush the line corresponding to the address r0 is holding
|
||||
add r0, #0x20
|
||||
cmp r0, r1
|
||||
blo flush_icache_range_loop
|
||||
|
||||
bx lr
|
||||
84
arm9/source/chainloader.c
Normal file
84
arm9/source/chainloader.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "chainloader.h"
|
||||
#include "screen.h"
|
||||
|
||||
void disableMpuAndJumpToEntrypoints(int argc, char **argv, void *arm11Entry, void *arm9Entry);
|
||||
|
||||
#pragma GCC optimize (3)
|
||||
|
||||
static void *xmemcpy(void *dst, const void *src, u32 len)
|
||||
{
|
||||
const u8 *src8 = (const u8 *)src;
|
||||
u8 *dst8 = (u8 *)dst;
|
||||
|
||||
for (u32 i = 0; i < len; i++) {
|
||||
dst8[i] = src8[i];
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
static void doLaunchFirm(Firm *firm, int argc, char **argv)
|
||||
{
|
||||
//Copy FIRM sections to respective memory locations
|
||||
for(u32 sectionNum = 0; sectionNum < 4; sectionNum++)
|
||||
xmemcpy(firm->section[sectionNum].address, (u8 *)firm + firm->section[sectionNum].offset, firm->section[sectionNum].size);
|
||||
|
||||
disableMpuAndJumpToEntrypoints(argc, argv, firm->arm9Entry, firm->arm11Entry);
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void chainloader_main(int argc, char **argv, Firm *firm)
|
||||
{
|
||||
char *argvPassed[2],
|
||||
absPath[24 + 255];
|
||||
struct fb fbs[2];
|
||||
|
||||
if(argc > 0)
|
||||
{
|
||||
u32 i;
|
||||
for(i = 0; i < sizeof(absPath) - 1 && argv[0][i] != 0; i++)
|
||||
absPath[i] = argv[0][i];
|
||||
absPath[i] = 0;
|
||||
|
||||
argvPassed[0] = (char *)absPath;
|
||||
}
|
||||
|
||||
if(argc == 2)
|
||||
{
|
||||
struct fb *fbsrc = (struct fb *)argv[1];
|
||||
|
||||
fbs[0] = fbsrc[0];
|
||||
fbs[1] = fbsrc[1];
|
||||
|
||||
argvPassed[1] = (char *)&fbs;
|
||||
}
|
||||
|
||||
doLaunchFirm(firm, argc, argvPassed);
|
||||
}
|
||||
32
arm9/source/chainloader.h
Normal file
32
arm9/source/chainloader.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "firm.h"
|
||||
|
||||
void chainload(int argc, char **argv, Firm *firm);
|
||||
439
arm9/source/config.c
Normal file
439
arm9/source/config.c
Normal file
@@ -0,0 +1,439 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "memory.h"
|
||||
#include "fs.h"
|
||||
#include "utils.h"
|
||||
#include "screen.h"
|
||||
#include "draw.h"
|
||||
#include "emunand.h"
|
||||
#include "buttons.h"
|
||||
#include "pin.h"
|
||||
|
||||
CfgData configData;
|
||||
ConfigurationStatus needConfig;
|
||||
static CfgData oldConfig;
|
||||
|
||||
bool readConfig(void)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
if(fileRead(&configData, CONFIG_FILE, sizeof(CfgData)) != sizeof(CfgData) ||
|
||||
memcmp(configData.magic, "CONF", 4) != 0 ||
|
||||
configData.formatVersionMajor != CONFIG_VERSIONMAJOR ||
|
||||
configData.formatVersionMinor != CONFIG_VERSIONMINOR)
|
||||
{
|
||||
memset(&configData, 0, sizeof(CfgData));
|
||||
|
||||
ret = false;
|
||||
}
|
||||
else ret = true;
|
||||
|
||||
oldConfig = configData;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void writeConfig(bool isConfigOptions)
|
||||
{
|
||||
//If the configuration is different from previously, overwrite it.
|
||||
if(needConfig != CREATE_CONFIGURATION && ((isConfigOptions && configData.config == oldConfig.config && configData.multiConfig == oldConfig.multiConfig) ||
|
||||
(!isConfigOptions && configData.bootConfig == oldConfig.bootConfig))) return;
|
||||
|
||||
if(needConfig == CREATE_CONFIGURATION)
|
||||
{
|
||||
memcpy(configData.magic, "CONF", 4);
|
||||
configData.formatVersionMajor = CONFIG_VERSIONMAJOR;
|
||||
configData.formatVersionMinor = CONFIG_VERSIONMINOR;
|
||||
|
||||
needConfig = MODIFY_CONFIGURATION;
|
||||
}
|
||||
|
||||
if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData)))
|
||||
error("Error writing the configuration file");
|
||||
}
|
||||
|
||||
void configMenu(bool oldPinStatus, u32 oldPinMode)
|
||||
{
|
||||
static const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )",
|
||||
"Screen brightness: 4( ) 3( ) 2( ) 1( )",
|
||||
"Splash: Off( ) Before( ) After( ) payloads",
|
||||
"Splash duration: 1( ) 3( ) 5( ) 7( ) seconds",
|
||||
"PIN lock: Off( ) 4( ) 6( ) 8( ) digits",
|
||||
"New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )",
|
||||
};
|
||||
|
||||
static const char *singleOptionsText[] = { "( ) Autoboot EmuNAND",
|
||||
"( ) Use EmuNAND FIRM if booting with R",
|
||||
"( ) Enable loading external FIRMs and modules",
|
||||
"( ) Enable game patching",
|
||||
"( ) Show NAND or user string in System Settings",
|
||||
"( ) Show GBA boot screen in patched AGB_FIRM",
|
||||
"( ) Set developer UNITINFO",
|
||||
"( ) Disable Arm11 exception handlers",
|
||||
"( ) Enable Rosalina on SAFE_FIRM",
|
||||
};
|
||||
|
||||
static const char *optionsDescription[] = { "Select the default EmuNAND.\n\n"
|
||||
"It will be booted when no\n"
|
||||
"directional pad buttons are pressed.",
|
||||
|
||||
"Select the screen brightness.",
|
||||
|
||||
"Enable splash screen support.\n\n"
|
||||
"\t* 'Before payloads' displays it\n"
|
||||
"before booting payloads\n"
|
||||
"(intended for splashes that display\n"
|
||||
"button hints).\n\n"
|
||||
"\t* 'After payloads' displays it\n"
|
||||
"afterwards.",
|
||||
|
||||
"Select how long the splash screen\n"
|
||||
"displays.\n\n"
|
||||
"This has no effect if the splash\n"
|
||||
"screen is not enabled.",
|
||||
|
||||
"Activate a PIN lock.\n\n"
|
||||
"The PIN will be asked each time\n"
|
||||
"Luma3DS boots.\n\n"
|
||||
"4, 6 or 8 digits can be selected.\n\n"
|
||||
"The ABXY buttons and the directional\n"
|
||||
"pad buttons can be used as keys.\n\n"
|
||||
"A message can also be displayed\n"
|
||||
"(refer to the wiki for instructions).",
|
||||
|
||||
"Select the New 3DS CPU mode.\n\n"
|
||||
"This won't apply to\n"
|
||||
"New 3DS exclusive/enhanced games.\n\n"
|
||||
"'Clock+L2' can cause issues with some\n"
|
||||
"games.",
|
||||
|
||||
"If enabled, an EmuNAND\n"
|
||||
"will be launched on boot.\n\n"
|
||||
"Otherwise, SysNAND will.\n\n"
|
||||
"Hold L on boot to switch NAND.\n\n"
|
||||
"To use a different EmuNAND from the\n"
|
||||
"default, hold a directional pad button\n"
|
||||
"(Up/Right/Down/Left equal EmuNANDs\n"
|
||||
"1/2/3/4).",
|
||||
|
||||
"If enabled, when holding R on boot\n"
|
||||
"SysNAND will be booted with an\n"
|
||||
"EmuNAND FIRM.\n\n"
|
||||
"Otherwise, an EmuNAND will be booted\n"
|
||||
"with the SysNAND FIRM.\n\n"
|
||||
"To use a different EmuNAND from the\n"
|
||||
"default, hold a directional pad button\n"
|
||||
"(Up/Right/Down/Left equal EmuNANDs\n"
|
||||
"1/2/3/4), also add A if you have\n"
|
||||
"a matching payload.",
|
||||
|
||||
"Enable loading external FIRMs and\n"
|
||||
"system modules.\n\n"
|
||||
"This isn't needed in most cases.\n\n"
|
||||
"Refer to the wiki for instructions.",
|
||||
|
||||
"Enable overriding the region and\n"
|
||||
"language configuration and the usage\n"
|
||||
"of patched code binaries, exHeaders,\n"
|
||||
"IPS code patches and LayeredFS\n"
|
||||
"for specific games.\n\n"
|
||||
"Also makes certain DLCs\n"
|
||||
"for out-of-region games work.\n\n"
|
||||
"Refer to the wiki for instructions.",
|
||||
|
||||
"Enable showing the current NAND/FIRM:\n\n"
|
||||
"\t* Sys = SysNAND\n"
|
||||
"\t* Emu = EmuNAND 1\n"
|
||||
"\t* EmuX = EmuNAND X\n"
|
||||
"\t* SysE = SysNAND with EmuNAND 1 FIRM\n"
|
||||
"\t* SyEX = SysNAND with EmuNAND X FIRM\n"
|
||||
"\t* EmuS = EmuNAND 1 with SysNAND FIRM\n"
|
||||
"\t* EmXS = EmuNAND X with SysNAND FIRM\n\n"
|
||||
"or a user-defined custom string in\n"
|
||||
"System Settings.\n\n"
|
||||
"Refer to the wiki for instructions.",
|
||||
|
||||
"Enable showing the GBA boot screen\n"
|
||||
"when booting GBA games.",
|
||||
|
||||
"Make the console be always detected\n"
|
||||
"as a development unit, and conversely.\n"
|
||||
"(which breaks online features, amiibo\n"
|
||||
"and retail CIAs, but allows installing\n"
|
||||
"and booting some developer software).\n\n"
|
||||
"Only select this if you know what you\n"
|
||||
"are doing!",
|
||||
|
||||
"Disables the fatal error exception\n"
|
||||
"handlers for the Arm11 CPU.\n\n"
|
||||
"Note: Disabling the exception handlers\n"
|
||||
"will disqualify you from submitting\n"
|
||||
"issues or bug reports to the Luma3DS\n"
|
||||
"GitHub repository!",
|
||||
|
||||
"Enables Rosalina, the kernel ext.\n"
|
||||
"and sysmodule reimplementations on\n"
|
||||
"SAFE_FIRM (New 3DS only).\n\n"
|
||||
"Also suppresses QTM error 0xF96183FE,\n"
|
||||
"allowing to use 8.1-11.3 N3DS on\n"
|
||||
"New 2DS XL consoles.\n\n"
|
||||
"Only select this if you know what you\n"
|
||||
"are doing!",
|
||||
};
|
||||
|
||||
FirmwareSource nandType = FIRMWARE_SYSNAND;
|
||||
if(isSdMode)
|
||||
{
|
||||
nandType = FIRMWARE_EMUNAND;
|
||||
locateEmuNand(&nandType);
|
||||
}
|
||||
|
||||
struct multiOption {
|
||||
u32 posXs[4];
|
||||
u32 posY;
|
||||
u32 enabled;
|
||||
bool visible;
|
||||
} multiOptions[] = {
|
||||
{ .visible = nandType == FIRMWARE_EMUNAND },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = ISN3DS },
|
||||
};
|
||||
|
||||
struct singleOption {
|
||||
u32 posY;
|
||||
bool enabled;
|
||||
bool visible;
|
||||
} singleOptions[] = {
|
||||
{ .visible = nandType == FIRMWARE_EMUNAND },
|
||||
{ .visible = nandType == FIRMWARE_EMUNAND },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = true },
|
||||
{ .visible = ISN3DS },
|
||||
};
|
||||
|
||||
//Calculate the amount of the various kinds of options and pre-select the first single one
|
||||
u32 multiOptionsAmount = sizeof(multiOptions) / sizeof(struct multiOption),
|
||||
singleOptionsAmount = sizeof(singleOptions) / sizeof(struct singleOption),
|
||||
totalIndexes = multiOptionsAmount + singleOptionsAmount - 1,
|
||||
selectedOption = 0,
|
||||
singleSelected = 0;
|
||||
bool isMultiOption = false;
|
||||
|
||||
//Parse the existing options
|
||||
for(u32 i = 0; i < multiOptionsAmount; i++)
|
||||
{
|
||||
//Detect the positions where the "x" should go
|
||||
u32 optionNum = 0;
|
||||
for(u32 j = 0; optionNum < 4 && j < strlen(multiOptionsText[i]); j++)
|
||||
if(multiOptionsText[i][j] == '(') multiOptions[i].posXs[optionNum++] = j + 1;
|
||||
while(optionNum < 4) multiOptions[i].posXs[optionNum++] = 0;
|
||||
|
||||
multiOptions[i].enabled = MULTICONFIG(i);
|
||||
}
|
||||
for(u32 i = 0; i < singleOptionsAmount; i++)
|
||||
singleOptions[i].enabled = CONFIG(i);
|
||||
|
||||
initScreens();
|
||||
|
||||
static const char *bootTypes[] = { "B9S",
|
||||
"B9S (ntrboot)",
|
||||
"FIRM0",
|
||||
"FIRM1" };
|
||||
|
||||
drawString(true, 10, 10, COLOR_TITLE, CONFIG_TITLE);
|
||||
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press A to select, START to save");
|
||||
drawFormattedString(false, 10, SCREEN_HEIGHT - 2 * SPACING_Y, COLOR_YELLOW, "Booted from %s via %s", isSdMode ? "SD" : "CTRNAND", bootTypes[(u32)bootType]);
|
||||
|
||||
//Character to display a selected option
|
||||
char selected = 'x';
|
||||
|
||||
u32 endPos = 10 + 2 * SPACING_Y;
|
||||
|
||||
//Display all the multiple choice options in white
|
||||
for(u32 i = 0; i < multiOptionsAmount; i++)
|
||||
{
|
||||
if(!multiOptions[i].visible) continue;
|
||||
|
||||
multiOptions[i].posY = endPos + SPACING_Y;
|
||||
endPos = drawString(true, 10, multiOptions[i].posY, COLOR_WHITE, multiOptionsText[i]);
|
||||
drawCharacter(true, 10 + multiOptions[i].posXs[multiOptions[i].enabled] * SPACING_X, multiOptions[i].posY, COLOR_WHITE, selected);
|
||||
}
|
||||
|
||||
endPos += SPACING_Y / 2;
|
||||
|
||||
//Display all the normal options in white except for the first one
|
||||
for(u32 i = 0, color = COLOR_RED; i < singleOptionsAmount; i++)
|
||||
{
|
||||
if(!singleOptions[i].visible) continue;
|
||||
|
||||
singleOptions[i].posY = endPos + SPACING_Y;
|
||||
endPos = drawString(true, 10, singleOptions[i].posY, color, singleOptionsText[i]);
|
||||
if(singleOptions[i].enabled) drawCharacter(true, 10 + SPACING_X, singleOptions[i].posY, color, selected);
|
||||
|
||||
if(color == COLOR_RED)
|
||||
{
|
||||
singleSelected = i;
|
||||
selectedOption = i + multiOptionsAmount;
|
||||
color = COLOR_WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
drawString(false, 10, 10, COLOR_WHITE, optionsDescription[selectedOption]);
|
||||
|
||||
//Boring configuration menu
|
||||
while(true)
|
||||
{
|
||||
u32 pressed;
|
||||
do
|
||||
{
|
||||
pressed = waitInput(true) & MENU_BUTTONS;
|
||||
}
|
||||
while(!pressed);
|
||||
|
||||
if(pressed == BUTTON_START) break;
|
||||
|
||||
if(pressed != BUTTON_A)
|
||||
{
|
||||
//Remember the previously selected option
|
||||
u32 oldSelectedOption = selectedOption;
|
||||
|
||||
while(true)
|
||||
{
|
||||
switch(pressed)
|
||||
{
|
||||
case BUTTON_UP:
|
||||
selectedOption = !selectedOption ? totalIndexes : selectedOption - 1;
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
selectedOption = selectedOption == totalIndexes ? 0 : selectedOption + 1;
|
||||
break;
|
||||
case BUTTON_LEFT:
|
||||
pressed = BUTTON_DOWN;
|
||||
selectedOption = 0;
|
||||
break;
|
||||
case BUTTON_RIGHT:
|
||||
pressed = BUTTON_UP;
|
||||
selectedOption = totalIndexes;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(selectedOption < multiOptionsAmount)
|
||||
{
|
||||
if(!multiOptions[selectedOption].visible) continue;
|
||||
|
||||
isMultiOption = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
singleSelected = selectedOption - multiOptionsAmount;
|
||||
|
||||
if(!singleOptions[singleSelected].visible) continue;
|
||||
|
||||
isMultiOption = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectedOption == oldSelectedOption) continue;
|
||||
|
||||
//The user moved to a different option, print the old option in white and the new one in red. Only print 'x's if necessary
|
||||
if(oldSelectedOption < multiOptionsAmount)
|
||||
{
|
||||
drawString(true, 10, multiOptions[oldSelectedOption].posY, COLOR_WHITE, multiOptionsText[oldSelectedOption]);
|
||||
drawCharacter(true, 10 + multiOptions[oldSelectedOption].posXs[multiOptions[oldSelectedOption].enabled] * SPACING_X, multiOptions[oldSelectedOption].posY, COLOR_WHITE, selected);
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 singleOldSelected = oldSelectedOption - multiOptionsAmount;
|
||||
drawString(true, 10, singleOptions[singleOldSelected].posY, COLOR_WHITE, singleOptionsText[singleOldSelected]);
|
||||
if(singleOptions[singleOldSelected].enabled) drawCharacter(true, 10 + SPACING_X, singleOptions[singleOldSelected].posY, COLOR_WHITE, selected);
|
||||
}
|
||||
|
||||
if(isMultiOption) drawString(true, 10, multiOptions[selectedOption].posY, COLOR_RED, multiOptionsText[selectedOption]);
|
||||
else drawString(true, 10, singleOptions[singleSelected].posY, COLOR_RED, singleOptionsText[singleSelected]);
|
||||
|
||||
drawString(false, 10, 10, COLOR_BLACK, optionsDescription[oldSelectedOption]);
|
||||
drawString(false, 10, 10, COLOR_WHITE, optionsDescription[selectedOption]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//The selected option's status changed, print the 'x's accordingly
|
||||
if(isMultiOption)
|
||||
{
|
||||
u32 oldEnabled = multiOptions[selectedOption].enabled;
|
||||
drawCharacter(true, 10 + multiOptions[selectedOption].posXs[oldEnabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_BLACK, selected);
|
||||
multiOptions[selectedOption].enabled = (oldEnabled == 3 || !multiOptions[selectedOption].posXs[oldEnabled + 1]) ? 0 : oldEnabled + 1;
|
||||
|
||||
if(selectedOption == BRIGHTNESS) updateBrightness(multiOptions[BRIGHTNESS].enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool oldEnabled = singleOptions[singleSelected].enabled;
|
||||
singleOptions[singleSelected].enabled = !oldEnabled;
|
||||
if(oldEnabled) drawCharacter(true, 10 + SPACING_X, singleOptions[singleSelected].posY, COLOR_BLACK, selected);
|
||||
}
|
||||
}
|
||||
|
||||
//In any case, if the current option is enabled (or a multiple choice option is selected) we must display a red 'x'
|
||||
if(isMultiOption) drawCharacter(true, 10 + multiOptions[selectedOption].posXs[multiOptions[selectedOption].enabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_RED, selected);
|
||||
else if(singleOptions[singleSelected].enabled) drawCharacter(true, 10 + SPACING_X, singleOptions[singleSelected].posY, COLOR_RED, selected);
|
||||
}
|
||||
|
||||
//Parse and write the new configuration
|
||||
configData.multiConfig = 0;
|
||||
for(u32 i = 0; i < multiOptionsAmount; i++)
|
||||
configData.multiConfig |= multiOptions[i].enabled << (i * 2);
|
||||
|
||||
configData.config = 0;
|
||||
for(u32 i = 0; i < singleOptionsAmount; i++)
|
||||
configData.config |= (singleOptions[i].enabled ? 1 : 0) << i;
|
||||
|
||||
writeConfig(true);
|
||||
|
||||
u32 newPinMode = MULTICONFIG(PIN);
|
||||
|
||||
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode);
|
||||
else if(oldPinStatus)
|
||||
{
|
||||
if(!fileDelete(PIN_FILE))
|
||||
error("Unable to delete PIN file");
|
||||
}
|
||||
|
||||
while(HID_PAD & PIN_BUTTONS);
|
||||
wait(2000ULL);
|
||||
}
|
||||
78
arm9/source/config.h
Normal file
78
arm9/source/config.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define CONFIG(a) (((configData.config >> (a)) & 1) != 0)
|
||||
#define MULTICONFIG(a) ((configData.multiConfig >> (2 * (a))) & 3)
|
||||
#define BOOTCONFIG(a, b) ((configData.bootConfig >> (a)) & (b))
|
||||
|
||||
#define CONFIG_FILE "config.bin"
|
||||
#define CONFIG_VERSIONMAJOR 2
|
||||
#define CONFIG_VERSIONMINOR 4
|
||||
|
||||
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
|
||||
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)
|
||||
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1)
|
||||
#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1)
|
||||
|
||||
enum multiOptions
|
||||
{
|
||||
DEFAULTEMU = 0,
|
||||
BRIGHTNESS,
|
||||
SPLASH,
|
||||
SPLASH_DURATION,
|
||||
PIN,
|
||||
NEWCPU
|
||||
};
|
||||
|
||||
enum singleOptions
|
||||
{
|
||||
AUTOBOOTEMU = 0,
|
||||
USEEMUFIRM,
|
||||
LOADEXTFIRMSANDMODULES,
|
||||
PATCHGAMES,
|
||||
PATCHVERSTRING,
|
||||
SHOWGBABOOT,
|
||||
PATCHUNITINFO,
|
||||
DISABLEARM11EXCHANDLERS,
|
||||
ENABLESAFEFIRMROSALINA,
|
||||
};
|
||||
|
||||
typedef enum ConfigurationStatus
|
||||
{
|
||||
DONT_CONFIGURE = 0,
|
||||
MODIFY_CONFIGURATION,
|
||||
CREATE_CONFIGURATION
|
||||
} ConfigurationStatus;
|
||||
|
||||
extern CfgData configData;
|
||||
|
||||
bool readConfig(void);
|
||||
void writeConfig(bool isConfigOptions);
|
||||
void configMenu(bool oldPinStatus, u32 oldPinMode);
|
||||
618
arm9/source/crypto.c
Executable file
618
arm9/source/crypto.c
Executable file
@@ -0,0 +1,618 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Crypto libs from http://github.com/b1l1s/ctr
|
||||
* kernel9Loader code originally adapted from https://github.com/Reisyukaku/ReiNand/blob/228c378255ba693133dec6f3368e14d386f2cde7/source/crypto.c#L233
|
||||
* decryptNusFirm code adapted from https://github.com/mid-kid/CakesForeveryWan/blob/master/source/firm.c
|
||||
* ctrNandWrite logic adapted from https://github.com/d0k3/GodMode9/blob/master/source/nand/nand.c
|
||||
*/
|
||||
|
||||
#include "crypto.h"
|
||||
#include "memory.h"
|
||||
#include "emunand.h"
|
||||
#include "utils.h"
|
||||
#include "alignedseqmemcpy.h"
|
||||
#include "strings.h"
|
||||
#include "fatfs/sdmmc/sdmmc.h"
|
||||
|
||||
/****************************************************************
|
||||
* Crypto libs
|
||||
****************************************************************/
|
||||
|
||||
/* original version by megazig */
|
||||
|
||||
#ifndef __thumb__
|
||||
#define BSWAP32(x) {\
|
||||
__asm__\
|
||||
(\
|
||||
"eor r1, %1, %1, ror #16\n\t"\
|
||||
"bic r1, r1, #0xFF0000\n\t"\
|
||||
"mov %0, %1, ror #8\n\t"\
|
||||
"eor %0, %0, r1, lsr #8\n\t"\
|
||||
:"=r"(x)\
|
||||
:"0"(x)\
|
||||
:"r1"\
|
||||
);\
|
||||
};
|
||||
|
||||
#define ADD_u128_u32(u128_0, u128_1, u128_2, u128_3, u32_0) {\
|
||||
__asm__\
|
||||
(\
|
||||
"adds %0, %4\n\t"\
|
||||
"addcss %1, %1, #1\n\t"\
|
||||
"addcss %2, %2, #1\n\t"\
|
||||
"addcs %3, %3, #1\n\t"\
|
||||
: "+r"(u128_0), "+r"(u128_1), "+r"(u128_2), "+r"(u128_3)\
|
||||
: "r"(u32_0)\
|
||||
: "cc"\
|
||||
);\
|
||||
}
|
||||
#else
|
||||
#define BSWAP32(x) {x = __builtin_bswap32(x);}
|
||||
|
||||
#define ADD_u128_u32(u128_0, u128_1, u128_2, u128_3, u32_0) {\
|
||||
__asm__\
|
||||
(\
|
||||
"mov r4, #0\n\t"\
|
||||
"add %0, %0, %4\n\t"\
|
||||
"adc %1, %1, r4\n\t"\
|
||||
"adc %2, %2, r4\n\t"\
|
||||
"adc %3, %3, r4\n\t"\
|
||||
: "+r"(u128_0), "+r"(u128_1), "+r"(u128_2), "+r"(u128_3)\
|
||||
: "r"(u32_0)\
|
||||
: "cc", "r4"\
|
||||
);\
|
||||
}
|
||||
#endif /*__thumb__*/
|
||||
|
||||
static void aes_setkey(u8 keyslot, const void *key, u32 keyType, u32 mode)
|
||||
{
|
||||
u32 *key32 = (u32 *)key;
|
||||
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER)) | mode;
|
||||
|
||||
if(keyslot <= 3)
|
||||
{
|
||||
if((mode & AES_CNT_INPUT_ORDER) == AES_INPUT_TWLREVERSED)
|
||||
{
|
||||
REGs_AESTWLKEYS[keyslot][keyType][0] = key32[3];
|
||||
REGs_AESTWLKEYS[keyslot][keyType][1] = key32[2];
|
||||
REGs_AESTWLKEYS[keyslot][keyType][2] = key32[1];
|
||||
REGs_AESTWLKEYS[keyslot][keyType][3] = key32[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
REGs_AESTWLKEYS[keyslot][keyType][0] = key32[0];
|
||||
REGs_AESTWLKEYS[keyslot][keyType][1] = key32[1];
|
||||
REGs_AESTWLKEYS[keyslot][keyType][2] = key32[2];
|
||||
REGs_AESTWLKEYS[keyslot][keyType][3] = key32[3];
|
||||
}
|
||||
}
|
||||
|
||||
else if(keyslot < 0x40)
|
||||
{
|
||||
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | AES_KEYCNT_WRITE;
|
||||
|
||||
REG_AESKEYFIFO[keyType] = key32[0];
|
||||
REG_AESKEYFIFO[keyType] = key32[1];
|
||||
REG_AESKEYFIFO[keyType] = key32[2];
|
||||
REG_AESKEYFIFO[keyType] = key32[3];
|
||||
}
|
||||
}
|
||||
|
||||
static void aes_use_keyslot(u8 keyslot)
|
||||
{
|
||||
if(keyslot > 0x3F)
|
||||
return;
|
||||
|
||||
*REG_AESKEYSEL = keyslot;
|
||||
*REG_AESCNT = *REG_AESCNT | 0x04000000; /* mystery bit */
|
||||
}
|
||||
|
||||
static void aes_setiv(const void *iv, u32 mode)
|
||||
{
|
||||
const u32 *iv32 = (const u32 *)iv;
|
||||
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER)) | mode;
|
||||
|
||||
//Word order for IV can't be changed in REG_AESCNT and always default to reversed
|
||||
if(mode & AES_INPUT_NORMAL)
|
||||
{
|
||||
REG_AESCTR[0] = iv32[3];
|
||||
REG_AESCTR[1] = iv32[2];
|
||||
REG_AESCTR[2] = iv32[1];
|
||||
REG_AESCTR[3] = iv32[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
REG_AESCTR[0] = iv32[0];
|
||||
REG_AESCTR[1] = iv32[1];
|
||||
REG_AESCTR[2] = iv32[2];
|
||||
REG_AESCTR[3] = iv32[3];
|
||||
}
|
||||
}
|
||||
|
||||
static void aes_advctr(void *ctr, u32 val, u32 mode)
|
||||
{
|
||||
u32 *ctr32 = (u32 *)ctr;
|
||||
|
||||
int i;
|
||||
if(mode & AES_INPUT_BE)
|
||||
{
|
||||
for(i = 0; i < 4; ++i) //Endian swap
|
||||
BSWAP32(ctr32[i]);
|
||||
}
|
||||
|
||||
if(mode & AES_INPUT_NORMAL)
|
||||
{
|
||||
ADD_u128_u32(ctr32[3], ctr32[2], ctr32[1], ctr32[0], val);
|
||||
}
|
||||
else
|
||||
{
|
||||
ADD_u128_u32(ctr32[0], ctr32[1], ctr32[2], ctr32[3], val);
|
||||
}
|
||||
|
||||
if(mode & AES_INPUT_BE)
|
||||
{
|
||||
for(i = 0; i < 4; ++i) //Endian swap
|
||||
BSWAP32(ctr32[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void aes_change_ctrmode(void *ctr, u32 fromMode, u32 toMode)
|
||||
{
|
||||
u32 *ctr32 = (u32 *)ctr;
|
||||
int i;
|
||||
if((fromMode ^ toMode) & AES_CNT_INPUT_ENDIAN)
|
||||
{
|
||||
for(i = 0; i < 4; ++i)
|
||||
BSWAP32(ctr32[i]);
|
||||
}
|
||||
|
||||
if((fromMode ^ toMode) & AES_CNT_INPUT_ORDER)
|
||||
{
|
||||
u32 temp = ctr32[0];
|
||||
ctr32[0] = ctr32[3];
|
||||
ctr32[3] = temp;
|
||||
|
||||
temp = ctr32[1];
|
||||
ctr32[1] = ctr32[2];
|
||||
ctr32[2] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
static void aes_batch(void *dst, const void *src, u32 blockCount)
|
||||
{
|
||||
*REG_AESBLKCNT = blockCount << 16;
|
||||
*REG_AESCNT |= AES_CNT_START;
|
||||
|
||||
const u32 *src32 = (const u32 *)src;
|
||||
u32 *dst32 = (u32 *)dst;
|
||||
|
||||
u32 wbc = blockCount;
|
||||
u32 rbc = blockCount;
|
||||
|
||||
while(rbc)
|
||||
{
|
||||
if(wbc && ((*REG_AESCNT & 0x1F) <= 0xC)) //There's space for at least 4 ints
|
||||
{
|
||||
*REG_AESWRFIFO = *src32++;
|
||||
*REG_AESWRFIFO = *src32++;
|
||||
*REG_AESWRFIFO = *src32++;
|
||||
*REG_AESWRFIFO = *src32++;
|
||||
wbc--;
|
||||
}
|
||||
|
||||
if(rbc && ((*REG_AESCNT & (0x1F << 0x5)) >= (0x4 << 0x5))) //At least 4 ints available for read
|
||||
{
|
||||
*dst32++ = *REG_AESRDFIFO;
|
||||
*dst32++ = *REG_AESRDFIFO;
|
||||
*dst32++ = *REG_AESRDFIFO;
|
||||
*dst32++ = *REG_AESRDFIFO;
|
||||
rbc--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void aes(void *dst, const void *src, u32 blockCount, void *iv, u32 mode, u32 ivMode)
|
||||
{
|
||||
*REG_AESCNT = mode |
|
||||
AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER |
|
||||
AES_CNT_INPUT_ENDIAN | AES_CNT_OUTPUT_ENDIAN |
|
||||
AES_CNT_FLUSH_READ | AES_CNT_FLUSH_WRITE;
|
||||
|
||||
u32 blocks;
|
||||
while(blockCount != 0)
|
||||
{
|
||||
if((mode & AES_ALL_MODES) != AES_ECB_ENCRYPT_MODE
|
||||
&& (mode & AES_ALL_MODES) != AES_ECB_DECRYPT_MODE)
|
||||
aes_setiv(iv, ivMode);
|
||||
|
||||
blocks = (blockCount >= 0xFFFF) ? 0xFFFF : blockCount;
|
||||
|
||||
//Save the last block for the next decryption CBC batch's iv
|
||||
if((mode & AES_ALL_MODES) == AES_CBC_DECRYPT_MODE)
|
||||
{
|
||||
memcpy(iv, src + (blocks - 1) * AES_BLOCK_SIZE, AES_BLOCK_SIZE);
|
||||
aes_change_ctrmode(iv, AES_INPUT_BE | AES_INPUT_NORMAL, ivMode);
|
||||
}
|
||||
|
||||
//Process the current batch
|
||||
aes_batch(dst, src, blocks);
|
||||
|
||||
//Save the last block for the next encryption CBC batch's iv
|
||||
if((mode & AES_ALL_MODES) == AES_CBC_ENCRYPT_MODE)
|
||||
{
|
||||
memcpy(iv, dst + (blocks - 1) * AES_BLOCK_SIZE, AES_BLOCK_SIZE);
|
||||
aes_change_ctrmode(iv, AES_INPUT_BE | AES_INPUT_NORMAL, ivMode);
|
||||
}
|
||||
|
||||
//Advance counter for CTR mode
|
||||
else if((mode & AES_ALL_MODES) == AES_CTR_MODE)
|
||||
aes_advctr(iv, blocks, ivMode);
|
||||
|
||||
src += blocks * AES_BLOCK_SIZE;
|
||||
dst += blocks * AES_BLOCK_SIZE;
|
||||
blockCount -= blocks;
|
||||
}
|
||||
}
|
||||
|
||||
static void sha_wait_idle()
|
||||
{
|
||||
while(*REG_SHA_CNT & 1);
|
||||
}
|
||||
|
||||
void sha(void *res, const void *src, u32 size, u32 mode)
|
||||
{
|
||||
sha_wait_idle();
|
||||
*REG_SHA_CNT = mode | SHA_CNT_OUTPUT_ENDIAN | SHA_NORMAL_ROUND;
|
||||
|
||||
const u8 *src8 = (const u8 *)src;
|
||||
while(size >= 0x40)
|
||||
{
|
||||
sha_wait_idle();
|
||||
alignedseqmemcpy((void *)REG_SHA_INFIFO, src8, 0x40);
|
||||
|
||||
src8 += 0x40;
|
||||
size -= 0x40;
|
||||
}
|
||||
|
||||
sha_wait_idle();
|
||||
alignedseqmemcpy((void *)REG_SHA_INFIFO, src8, size);
|
||||
|
||||
*REG_SHA_CNT = (*REG_SHA_CNT & ~SHA_NORMAL_ROUND) | SHA_FINAL_ROUND;
|
||||
|
||||
while(*REG_SHA_CNT & SHA_FINAL_ROUND);
|
||||
sha_wait_idle();
|
||||
|
||||
u32 hashSize = SHA_256_HASH_SIZE;
|
||||
if(mode == SHA_224_MODE)
|
||||
hashSize = SHA_224_HASH_SIZE;
|
||||
else if(mode == SHA_1_MODE)
|
||||
hashSize = SHA_1_HASH_SIZE;
|
||||
|
||||
alignedseqmemcpy(res, (void *)REG_SHA_HASH, hashSize);
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
||||
__attribute__((aligned(4))) static u8 nandCtr[AES_BLOCK_SIZE];
|
||||
static u8 nandSlot;
|
||||
static u32 fatStart = 0;
|
||||
|
||||
FirmwareSource firmSource = FIRMWARE_SYSNAND;
|
||||
|
||||
__attribute__((aligned(4))) static const u8 key1s[2][AES_BLOCK_SIZE] = {
|
||||
{0x07, 0x29, 0x44, 0x38, 0xF8, 0xC9, 0x75, 0x93, 0xAA, 0x0E, 0x4A, 0xB4, 0xAE, 0x84, 0xC1, 0xD8},
|
||||
{0xA2, 0xF4, 0x00, 0x3C, 0x7A, 0x95, 0x10, 0x25, 0xDF, 0x4E, 0x9E, 0x74, 0xE3, 0x0C, 0x92, 0x99}
|
||||
},
|
||||
key2s[2][AES_BLOCK_SIZE] = {
|
||||
{0x42, 0x3F, 0x81, 0x7A, 0x23, 0x52, 0x58, 0x31, 0x6E, 0x75, 0x8E, 0x3A, 0x39, 0x43, 0x2E, 0xD0},
|
||||
{0xFF, 0x77, 0xA0, 0x9A, 0x99, 0x81, 0xE9, 0x48, 0xEC, 0x51, 0xC9, 0x32, 0x5D, 0x14, 0xEC, 0x25}
|
||||
};
|
||||
|
||||
int ctrNandInit(void)
|
||||
{
|
||||
__attribute__((aligned(4))) u8 cid[AES_BLOCK_SIZE],
|
||||
shaSum[SHA_256_HASH_SIZE];
|
||||
|
||||
sdmmc_get_cid(1, (u32 *)cid);
|
||||
sha(shaSum, cid, sizeof(cid), SHA_256_MODE);
|
||||
memcpy(nandCtr, shaSum, sizeof(nandCtr));
|
||||
|
||||
nandSlot = ISN3DS ? 0x05 : 0x04;
|
||||
|
||||
int result;
|
||||
u8 __attribute__((aligned(4))) temp[0x200];
|
||||
|
||||
//Read NCSD header
|
||||
result = firmSource == FIRMWARE_SYSNAND ? sdmmc_nand_readsectors(0, 1, temp) : sdmmc_sdcard_readsectors(emuHeader, 1, temp);
|
||||
|
||||
if(!result)
|
||||
{
|
||||
u32 partitionNum = 1; //TWL partitions need to be first
|
||||
for(u8 *partitionId = temp + 0x111; *partitionId != 1; partitionId++, partitionNum++);
|
||||
|
||||
u32 ctrMbrOffset = *((u32 *)(temp + 0x120) + (2 * partitionNum));
|
||||
|
||||
//Read CTR MBR
|
||||
result = ctrNandRead(ctrMbrOffset, 1, temp);
|
||||
|
||||
//Calculate final CTRNAND FAT offset
|
||||
if(!result) fatStart = ctrMbrOffset + *(u32 *)(temp + 0x1C6);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ctrNandRead(u32 sector, u32 sectorCount, u8 *outbuf)
|
||||
{
|
||||
__attribute__((aligned(4))) u8 tmpCtr[sizeof(nandCtr)];
|
||||
memcpy(tmpCtr, nandCtr, sizeof(nandCtr));
|
||||
aes_advctr(tmpCtr, ((sector + fatStart) * 0x200) / AES_BLOCK_SIZE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
//Read
|
||||
int result;
|
||||
if(firmSource == FIRMWARE_SYSNAND)
|
||||
result = sdmmc_nand_readsectors(sector + fatStart, sectorCount, outbuf);
|
||||
else
|
||||
{
|
||||
sector += emuOffset;
|
||||
result = sdmmc_sdcard_readsectors(sector + fatStart, sectorCount, outbuf);
|
||||
}
|
||||
|
||||
//Decrypt
|
||||
aes_use_keyslot(nandSlot);
|
||||
aes(outbuf, outbuf, sectorCount * 0x200 / AES_BLOCK_SIZE, tmpCtr, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ctrNandWrite(u32 sector, u32 sectorCount, const u8 *inbuf)
|
||||
{
|
||||
u8 *buffer = (u8 *)0xFFF00000;
|
||||
u32 bufferSize = 0x4000;
|
||||
|
||||
__attribute__((aligned(4))) u8 tmpCtr[sizeof(nandCtr)];
|
||||
memcpy(tmpCtr, nandCtr, sizeof(nandCtr));
|
||||
aes_advctr(tmpCtr, ((sector + fatStart) * 0x200) / AES_BLOCK_SIZE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_use_keyslot(nandSlot);
|
||||
|
||||
int result = 0;
|
||||
for(u32 tempSector = 0; tempSector < sectorCount && !result; tempSector += bufferSize / 0x200)
|
||||
{
|
||||
u32 tempCount = (bufferSize / 0x200) < (sectorCount - tempSector) ? (bufferSize / 0x200) : (sectorCount - tempSector);
|
||||
|
||||
memcpy(buffer, inbuf + (tempSector * 0x200), tempCount * 0x200);
|
||||
|
||||
//Encrypt
|
||||
aes(buffer, buffer, tempCount * 0x200 / AES_BLOCK_SIZE, tmpCtr, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
//Write
|
||||
result = sdmmc_nand_writesectors(tempSector + sector + fatStart, tempCount, buffer);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
u32 decryptExeFs(Cxi *cxi)
|
||||
{
|
||||
if(memcmp(cxi->ncch.magic, "NCCH", 4) != 0) return 0;
|
||||
|
||||
if(cxi->ncch.exeFsOffset != 5) return 0;
|
||||
|
||||
u8 *exeFsOffset = (u8 *)cxi + 6 * 0x200;
|
||||
u32 exeFsSize = (cxi->ncch.exeFsSize - 1) * 0x200;
|
||||
|
||||
if(exeFsSize > 0x400000) return 0;
|
||||
|
||||
__attribute__((aligned(4))) u8 ncchCtr[AES_BLOCK_SIZE] = {0};
|
||||
|
||||
for(u32 i = 0; i < 8; i++)
|
||||
ncchCtr[7 - i] = cxi->ncch.partitionId[i];
|
||||
ncchCtr[8] = 2;
|
||||
|
||||
aes_setkey(0x2C, cxi, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_advctr(ncchCtr, 0x200 / AES_BLOCK_SIZE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_use_keyslot(0x2C);
|
||||
aes(cxi, exeFsOffset, exeFsSize / AES_BLOCK_SIZE, ncchCtr, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
return memcmp(cxi, "FIRM", 4) == 0 ? exeFsSize : 0;
|
||||
}
|
||||
|
||||
u32 decryptNusFirm(const Ticket *ticket, Cxi *cxi, u32 ncchSize)
|
||||
{
|
||||
if(memcmp(ticket->sigIssuer, "Root", 4) != 0) return 0;
|
||||
|
||||
__attribute__((aligned(4))) static const u8 keyY0x3D[AES_BLOCK_SIZE] = {0x0C, 0x76, 0x72, 0x30, 0xF0, 0x99, 0x8F, 0x1C, 0x46, 0x82, 0x82, 0x02, 0xFA, 0xAC, 0xBE, 0x4C};
|
||||
__attribute__((aligned(4))) u8 titleKey[AES_BLOCK_SIZE],
|
||||
cetkIv[AES_BLOCK_SIZE] = {0};
|
||||
memcpy(titleKey, ticket->titleKey, sizeof(titleKey));
|
||||
memcpy(cetkIv, ticket->titleId, sizeof(ticket->titleId));
|
||||
|
||||
aes_setkey(0x3D, keyY0x3D, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_use_keyslot(0x3D);
|
||||
aes(titleKey, titleKey, 1, cetkIv, AES_CBC_DECRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
__attribute__((aligned(4))) u8 ncchIv[AES_BLOCK_SIZE] = {0};
|
||||
|
||||
aes_setkey(0x16, titleKey, AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_use_keyslot(0x16);
|
||||
aes(cxi, cxi, ncchSize / AES_BLOCK_SIZE, ncchIv, AES_CBC_DECRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
return decryptExeFs(cxi);
|
||||
}
|
||||
|
||||
static inline void twlConsoleInfoInit(void)
|
||||
{
|
||||
u64 twlConsoleId = ISDEVUNIT ? OTP_DEVCONSOLEID : (0x80000000ULL | (*(vu64 *)0x01FFB808 ^ 0x8C267B7B358A6AFULL));
|
||||
CFG_TWLUNITINFO = CFG_UNITINFO;
|
||||
OTP_TWLCONSOLEID = twlConsoleId;
|
||||
|
||||
*REG_AESCNT = 0;
|
||||
|
||||
vu32 *k3X = REGs_AESTWLKEYS[3][1],
|
||||
*k1X = REGs_AESTWLKEYS[1][1];
|
||||
|
||||
k3X[0] = (u32)twlConsoleId;
|
||||
k3X[3] = (u32)(twlConsoleId >> 32);
|
||||
|
||||
k1X[2] = (u32)(twlConsoleId >> 32);
|
||||
k1X[3] = (u32)twlConsoleId;
|
||||
|
||||
aes_setkey(2, (u8 *)0x01FFD398, AES_KEYX, AES_INPUT_TWLNORMAL);
|
||||
if(CFG_TWLUNITINFO != 0)
|
||||
{
|
||||
__attribute__((aligned(4))) static const u8 key2YDev[AES_BLOCK_SIZE] = {0x3B, 0x06, 0x86, 0x57, 0x33, 0x04, 0x88, 0x11, 0x49, 0x04, 0x6B, 0x33, 0x12, 0x02, 0xAC, 0xF3},
|
||||
key3YDev[AES_BLOCK_SIZE] = {0xAA, 0xBF, 0x76, 0xF1, 0x7A, 0xB8, 0xE8, 0x66, 0x97, 0x64, 0x6A, 0x26, 0x05, 0x00, 0xA0, 0xE1};
|
||||
|
||||
k3X[1] = 0xEE7A4B1E;
|
||||
k3X[2] = 0xAF42C08B;
|
||||
aes_setkey(2, key2YDev, AES_KEYY, AES_INPUT_TWLNORMAL);
|
||||
aes_setkey(3, key3YDev, AES_KEYY, AES_INPUT_TWLNORMAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 last3YWord = 0xE1A00005;
|
||||
__attribute__((aligned(4))) u8 key3YRetail[AES_BLOCK_SIZE];
|
||||
|
||||
memcpy(key3YRetail, (u8 *)0x01FFD3C8, 12);
|
||||
memcpy(key3YRetail + 12, &last3YWord, 4);
|
||||
|
||||
k3X[1] = *(vu32 *)0x01FFD3A8; //"NINT"
|
||||
k3X[2] = *(vu32 *)0x01FFD3AC; //"ENDO"
|
||||
aes_setkey(2, (u8 *)0x01FFD220, AES_KEYY, AES_INPUT_TWLNORMAL);
|
||||
aes_setkey(3, key3YRetail, AES_KEYY, AES_INPUT_TWLNORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
void setupKeyslots(void)
|
||||
{
|
||||
//Setup 0x24 KeyY
|
||||
__attribute__((aligned(4))) static const u8 keyY0x24[AES_BLOCK_SIZE] = {0x74, 0xCA, 0x07, 0x48, 0x84, 0xF4, 0x22, 0x8D, 0xEB, 0x2A, 0x1C, 0xA7, 0x2D, 0x28, 0x77, 0x62};
|
||||
aes_setkey(0x24, keyY0x24, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
//Setup 0x25 KeyX and 0x2F KeyY
|
||||
__attribute__((aligned(4))) static const u8 keyX0x25s[2][AES_BLOCK_SIZE] = {
|
||||
{0xCE, 0xE7, 0xD8, 0xAB, 0x30, 0xC0, 0x0D, 0xAE, 0x85, 0x0E, 0xF5, 0xE3, 0x82, 0xAC, 0x5A, 0xF3},
|
||||
{0x81, 0x90, 0x7A, 0x4B, 0x6F, 0x1B, 0x47, 0x32, 0x3A, 0x67, 0x79, 0x74, 0xCE, 0x4A, 0xD7, 0x1B}
|
||||
},
|
||||
keyY0x2Fs[2][AES_BLOCK_SIZE] = {
|
||||
{0xC3, 0x69, 0xBA, 0xA2, 0x1E, 0x18, 0x8A, 0x88, 0xA9, 0xAA, 0x94, 0xE5, 0x50, 0x6A, 0x9F, 0x16},
|
||||
{0x73, 0x25, 0xC4, 0xEB, 0x14, 0x3A, 0x0D, 0x5F, 0x5D, 0xB6, 0xE5, 0xC5, 0x7A, 0x21, 0x95, 0xAC}
|
||||
};
|
||||
|
||||
aes_setkey(0x25, keyX0x25s[ISDEVUNIT ? 1 : 0], AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_setkey(0x2F, keyY0x2Fs[ISDEVUNIT ? 1 : 0], AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
if(ISN3DS)
|
||||
{
|
||||
//Setup 0x05 KeyY
|
||||
__attribute__((aligned(4))) static const u8 keyY0x5[AES_BLOCK_SIZE] = {0x4D, 0x80, 0x4F, 0x4E, 0x99, 0x90, 0x19, 0x46, 0x13, 0xA2, 0x04, 0xAC, 0x58, 0x44, 0x60, 0xBE};
|
||||
aes_setkey(0x05, keyY0x5, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
}
|
||||
|
||||
//Setup TWL keys
|
||||
twlConsoleInfoInit();
|
||||
|
||||
__attribute__((aligned(4))) u8 keyBlocks[2][AES_BLOCK_SIZE] = {
|
||||
{0xA4, 0x8D, 0xE4, 0xF1, 0x0B, 0x36, 0x44, 0xAA, 0x90, 0x31, 0x28, 0xFF, 0x4D, 0xCA, 0x76, 0xDF},
|
||||
{0xDD, 0xDA, 0xA4, 0xC6, 0x2C, 0xC4, 0x50, 0xE9, 0xDA, 0xB6, 0x9B, 0x0D, 0x9D, 0x2A, 0x21, 0x98}
|
||||
}, decKey[AES_BLOCK_SIZE];
|
||||
|
||||
//Initialize Key 0x18
|
||||
aes_setkey(0x11, key1s[ISDEVUNIT ? 1 : 0], AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_use_keyslot(0x11);
|
||||
aes(decKey, keyBlocks[0], 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
||||
aes_setkey(0x18, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
//Initialize Key 0x19-0x1F
|
||||
aes_setkey(0x11, key2s[ISDEVUNIT ? 1 : 0], AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
aes_use_keyslot(0x11);
|
||||
for(u8 slot = 0x19; slot < 0x20; slot++, keyBlocks[1][0xF]++)
|
||||
{
|
||||
aes(decKey, keyBlocks[1], 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
||||
aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
void kernel9Loader(Arm9Bin *arm9Section)
|
||||
{
|
||||
//Determine the kernel9loader version
|
||||
u32 k9lVersion;
|
||||
switch(arm9Section->magic[3])
|
||||
{
|
||||
case 0xFF:
|
||||
k9lVersion = 0;
|
||||
break;
|
||||
case '1':
|
||||
k9lVersion = 1;
|
||||
break;
|
||||
default:
|
||||
k9lVersion = 2;
|
||||
}
|
||||
|
||||
u32 *startOfArm9Bin = (u32 *)((u8 *)arm9Section + 0x800);
|
||||
if(*startOfArm9Bin == 0x47704770 || *startOfArm9Bin == 0xB0862000) return; //Already decrypted
|
||||
|
||||
aes_setkey(0x11, k9lVersion == 2 ? key2s[ISDEVUNIT ? 1 : 0] : key1s[ISDEVUNIT ? 1 : 0], AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
u8 arm9BinSlot = k9lVersion == 0 ? 0x15 : 0x16;
|
||||
|
||||
// Get size
|
||||
u32 arm9SectionSize = decAtoi(arm9Section->size, 8);
|
||||
|
||||
//Set keyX
|
||||
__attribute__((aligned(4))) u8 keyX[AES_BLOCK_SIZE];
|
||||
aes_use_keyslot(0x11);
|
||||
aes(keyX, k9lVersion == 0 ? arm9Section->keyX : arm9Section->slot0x16keyX, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
||||
aes_setkey(arm9BinSlot, keyX, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
//Set keyY
|
||||
__attribute__((aligned(4))) u8 keyY[AES_BLOCK_SIZE];
|
||||
memcpy(keyY, arm9Section->keyY, sizeof(keyY));
|
||||
aes_setkey(arm9BinSlot, keyY, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
//Set CTR
|
||||
__attribute__((aligned(4))) u8 arm9BinCtr[AES_BLOCK_SIZE];
|
||||
memcpy(arm9BinCtr, arm9Section->ctr, sizeof(arm9BinCtr));
|
||||
|
||||
//Decrypt Arm9 binary
|
||||
aes_use_keyslot(arm9BinSlot);
|
||||
aes(startOfArm9Bin, startOfArm9Bin, arm9SectionSize / AES_BLOCK_SIZE, arm9BinCtr, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
|
||||
if(*startOfArm9Bin != 0x47704770 && *startOfArm9Bin != 0xB0862000) error("Failed to decrypt the Arm9 binary.");
|
||||
}
|
||||
|
||||
void computePinHash(u8 *outbuf, const u8 *inbuf)
|
||||
{
|
||||
__attribute__((aligned(4))) u8 cid[AES_BLOCK_SIZE],
|
||||
cipherText[AES_BLOCK_SIZE];
|
||||
|
||||
sdmmc_get_cid(1, (u32 *)cid);
|
||||
aes_use_keyslot(0x04); //Console-unique keyslot whose keys are set by the Arm9 bootROM
|
||||
aes(cipherText, inbuf, 1, cid, AES_CBC_ENCRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
sha(outbuf, cipherText, sizeof(cipherText), SHA_256_MODE);
|
||||
}
|
||||
124
arm9/source/crypto.h
Executable file
124
arm9/source/crypto.h
Executable file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Crypto libs from http://github.com/b1l1s/ctr
|
||||
* kernel9Loader code originally adapted from https://github.com/Reisyukaku/ReiNand/blob/228c378255ba693133dec6f3368e14d386f2cde7/source/crypto.c#L233
|
||||
* decryptNusFirm code adapted from https://github.com/mid-kid/CakesForeveryWan/blob/master/source/firm.c
|
||||
* ctrNandWrite logic adapted from https://github.com/d0k3/GodMode9/blob/master/source/nand/nand.c
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/**************************AES****************************/
|
||||
#define REG_AESCNT ((vu32 *)0x10009000)
|
||||
#define REG_AESBLKCNT ((vu32 *)0x10009004)
|
||||
#define REG_AESWRFIFO ((vu32 *)0x10009008)
|
||||
#define REG_AESRDFIFO ((vu32 *)0x1000900C)
|
||||
#define REG_AESKEYSEL ((vu8 *)0x10009010)
|
||||
#define REG_AESKEYCNT ((vu8 *)0x10009011)
|
||||
#define REG_AESCTR ((vu32 *)0x10009020)
|
||||
|
||||
#define REG_AESKEYFIFO ((vu32 *)0x10009100)
|
||||
#define REG_AESKEYXFIFO ((vu32 *)0x10009104)
|
||||
#define REG_AESKEYYFIFO ((vu32 *)0x10009108)
|
||||
|
||||
#define REGs_AESTWLKEYS (*((vu32 (*)[4][3][4])0x10009040))
|
||||
|
||||
#define AES_CCM_DECRYPT_MODE (0u << 27)
|
||||
#define AES_CCM_ENCRYPT_MODE (1u << 27)
|
||||
#define AES_CTR_MODE (2u << 27)
|
||||
#define AES_CTR_MODE (2u << 27)
|
||||
#define AES_CBC_DECRYPT_MODE (4u << 27)
|
||||
#define AES_CBC_ENCRYPT_MODE (5u << 27)
|
||||
#define AES_ECB_DECRYPT_MODE (6u << 27)
|
||||
#define AES_ECB_ENCRYPT_MODE (7u << 27)
|
||||
#define AES_ALL_MODES (7u << 27)
|
||||
|
||||
#define AES_CNT_START 0x80000000
|
||||
#define AES_CNT_INPUT_ORDER 0x02000000
|
||||
#define AES_CNT_OUTPUT_ORDER 0x01000000
|
||||
#define AES_CNT_INPUT_ENDIAN 0x00800000
|
||||
#define AES_CNT_OUTPUT_ENDIAN 0x00400000
|
||||
#define AES_CNT_FLUSH_READ 0x00000800
|
||||
#define AES_CNT_FLUSH_WRITE 0x00000400
|
||||
|
||||
#define AES_INPUT_BE (AES_CNT_INPUT_ENDIAN)
|
||||
#define AES_INPUT_LE 0
|
||||
#define AES_INPUT_NORMAL (AES_CNT_INPUT_ORDER)
|
||||
#define AES_INPUT_REVERSED 0
|
||||
#define AES_INPUT_TWLNORMAL 0
|
||||
#define AES_INPUT_TWLREVERSED (AES_CNT_INPUT_ORDER)
|
||||
|
||||
#define AES_BLOCK_SIZE 0x10
|
||||
|
||||
#define AES_KEYCNT_WRITE (1 << 0x7)
|
||||
#define AES_KEYNORMAL 0
|
||||
#define AES_KEYX 1
|
||||
#define AES_KEYY 2
|
||||
|
||||
/**************************SHA****************************/
|
||||
#define REG_SHA_CNT ((vu32 *)0x1000A000)
|
||||
#define REG_SHA_BLKCNT ((vu32 *)0x1000A004)
|
||||
#define REG_SHA_HASH ((vu32 *)0x1000A040)
|
||||
#define REG_SHA_INFIFO ((vu32 *)0x1000A080)
|
||||
|
||||
#define SHA_CNT_STATE 0x00000003
|
||||
#define SHA_CNT_UNK2 0x00000004
|
||||
#define SHA_CNT_OUTPUT_ENDIAN 0x00000008
|
||||
#define SHA_CNT_MODE 0x00000030
|
||||
#define SHA_CNT_ENABLE 0x00010000
|
||||
#define SHA_CNT_ACTIVE 0x00020000
|
||||
|
||||
#define SHA_HASH_READY 0x00000000
|
||||
#define SHA_NORMAL_ROUND 0x00000001
|
||||
#define SHA_FINAL_ROUND 0x00000002
|
||||
|
||||
#define SHA_OUTPUT_BE SHA_CNT_OUTPUT_ENDIAN
|
||||
#define SHA_OUTPUT_LE 0
|
||||
|
||||
#define SHA_256_MODE 0
|
||||
#define SHA_224_MODE 0x00000010
|
||||
#define SHA_1_MODE 0x00000020
|
||||
|
||||
#define SHA_256_HASH_SIZE (256 / 8)
|
||||
#define SHA_224_HASH_SIZE (224 / 8)
|
||||
#define SHA_1_HASH_SIZE (160 / 8)
|
||||
|
||||
extern FirmwareSource firmSource;
|
||||
|
||||
void sha(void *res, const void *src, u32 size, u32 mode);
|
||||
|
||||
int ctrNandInit(void);
|
||||
int ctrNandRead(u32 sector, u32 sectorCount, u8 *outbuf);
|
||||
int ctrNandWrite(u32 sector, u32 sectorCount, const u8 *inbuf);
|
||||
u32 decryptExeFs(Cxi *cxi);
|
||||
u32 decryptNusFirm(const Ticket *ticket, Cxi *cxi, u32 ncchSize);
|
||||
void setupKeyslots(void);
|
||||
void kernel9Loader(Arm9Bin *arm9Section);
|
||||
void computePinHash(u8 *outbuf, const u8 *inbuf);
|
||||
128
arm9/source/draw.c
Normal file
128
arm9/source/draw.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code to print to the screen by mid-kid @CakesFW
|
||||
* https://github.com/mid-kid/CakesForeveryWan
|
||||
*/
|
||||
|
||||
#include "draw.h"
|
||||
#include "memory.h"
|
||||
#include "screen.h"
|
||||
#include "utils.h"
|
||||
#include "fs.h"
|
||||
#include "fmt.h"
|
||||
#include "font.h"
|
||||
#include "config.h"
|
||||
|
||||
bool loadSplash(void)
|
||||
{
|
||||
static const char *topSplashFile = "splash.bin",
|
||||
*bottomSplashFile = "splashbottom.bin";
|
||||
|
||||
bool isTopSplashValid = getFileSize(topSplashFile) == SCREEN_TOP_FBSIZE,
|
||||
isBottomSplashValid = getFileSize(bottomSplashFile) == SCREEN_BOTTOM_FBSIZE;
|
||||
|
||||
//Don't delay boot nor init the screens if no splash images or invalid splash images are on the SD
|
||||
if(!isTopSplashValid && !isBottomSplashValid) return false;
|
||||
|
||||
initScreens();
|
||||
|
||||
if(isTopSplashValid) isTopSplashValid = fileRead(fbs[1].top_left, topSplashFile, SCREEN_TOP_FBSIZE) == SCREEN_TOP_FBSIZE;
|
||||
if(isBottomSplashValid) isBottomSplashValid = fileRead(fbs[1].bottom, bottomSplashFile, SCREEN_BOTTOM_FBSIZE) == SCREEN_BOTTOM_FBSIZE;
|
||||
|
||||
if(!isTopSplashValid && !isBottomSplashValid) return false;
|
||||
|
||||
swapFramebuffers(true);
|
||||
|
||||
u32 durationIndex = MULTICONFIG(SPLASH_DURATION);
|
||||
wait(1000ULL + (durationIndex * 2000ULL));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void drawCharacter(bool isTopScreen, u32 posX, u32 posY, u32 color, char character)
|
||||
{
|
||||
u8 *select = isTopScreen ? fbs[0].top_left : fbs[0].bottom;
|
||||
|
||||
for(u32 y = 0; y < 8; y++)
|
||||
{
|
||||
char charPos = font[character * 8 + y];
|
||||
|
||||
for(u32 x = 0; x < 8; x++)
|
||||
if(((charPos >> (7 - x)) & 1) == 1)
|
||||
{
|
||||
u32 screenPos = (posX * SCREEN_HEIGHT * 3 + (SCREEN_HEIGHT - y - posY - 1) * 3) + x * 3 * SCREEN_HEIGHT;
|
||||
|
||||
select[screenPos] = color >> 16;
|
||||
select[screenPos + 1] = color >> 8;
|
||||
select[screenPos + 2] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 drawString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *string)
|
||||
{
|
||||
for(u32 i = 0, line_i = 0; i < strlen(string); i++)
|
||||
switch(string[i])
|
||||
{
|
||||
case '\n':
|
||||
posY += SPACING_Y;
|
||||
line_i = 0;
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
line_i += 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
//Make sure we never get out of the screen
|
||||
if(line_i >= ((isTopScreen ? SCREEN_TOP_WIDTH : SCREEN_BOTTOM_WIDTH) - posX) / SPACING_X)
|
||||
{
|
||||
posY += SPACING_Y;
|
||||
line_i = 1; //Little offset so we know the same string continues
|
||||
if(string[i] == ' ') break; //Spaces at the start look weird
|
||||
}
|
||||
|
||||
drawCharacter(isTopScreen, posX + line_i * SPACING_X, posY, color, string[i]);
|
||||
|
||||
line_i++;
|
||||
break;
|
||||
}
|
||||
|
||||
return posY;
|
||||
}
|
||||
|
||||
u32 drawFormattedString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *fmt, ...)
|
||||
{
|
||||
char buf[DRAW_MAX_FORMATTED_STRING_SIZE + 1];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return drawString(isTopScreen, posX, posY, color, buf);
|
||||
}
|
||||
50
arm9/source/draw.h
Normal file
50
arm9/source/draw.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code to print to the screen by mid-kid @CakesFW
|
||||
* https://github.com/mid-kid/CakesForeveryWan/
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define SPACING_Y 10
|
||||
#define SPACING_X 8
|
||||
|
||||
#define COLOR_TITLE 0xFF9900
|
||||
#define COLOR_WHITE 0xFFFFFF
|
||||
#define COLOR_RED 0x0000FF
|
||||
#define COLOR_BLACK 0x000000
|
||||
#define COLOR_YELLOW 0x00FFFF
|
||||
|
||||
#define DRAW_MAX_FORMATTED_STRING_SIZE 512
|
||||
|
||||
bool loadSplash(void);
|
||||
void drawCharacter(bool isTopScreen, u32 posX, u32 posY, u32 color, char character);
|
||||
u32 drawString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *string);
|
||||
u32 drawFormattedString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *fmt, ...);
|
||||
218
arm9/source/emunand.c
Normal file
218
arm9/source/emunand.c
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code for locating the SDMMC struct by Normmatt
|
||||
*/
|
||||
|
||||
|
||||
#include "emunand.h"
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
#include "fatfs/sdmmc/sdmmc.h"
|
||||
#include "large_patches.h"
|
||||
|
||||
u32 emuOffset,
|
||||
emuHeader;
|
||||
|
||||
void locateEmuNand(FirmwareSource *nandType)
|
||||
{
|
||||
static u8 __attribute__((aligned(4))) temp[0x200];
|
||||
static u32 nandSize = 0,
|
||||
fatStart;
|
||||
|
||||
if(!nandSize)
|
||||
{
|
||||
nandSize = getMMCDevice(0)->total_size;
|
||||
sdmmc_sdcard_readsectors(0, 1, temp);
|
||||
fatStart = *(u32 *)(temp + 0x1C6); //First sector of the FAT partition
|
||||
}
|
||||
|
||||
for(u32 i = 0; i < 3; i++)
|
||||
{
|
||||
static const u32 roundedMinsizes[] = {0x1D8000, 0x26E000};
|
||||
|
||||
u32 nandOffset;
|
||||
switch(i)
|
||||
{
|
||||
case 1:
|
||||
nandOffset = ROUND_TO_4MB(nandSize + 1); //"Default" layout
|
||||
break;
|
||||
case 2:
|
||||
nandOffset = roundedMinsizes[ISN3DS ? 1 : 0]; //"Minsize" layout
|
||||
break;
|
||||
case 0:
|
||||
nandOffset = *nandType == FIRMWARE_EMUNAND ? 0 : (nandSize > 0x200000 ? 0x400000 : 0x200000); //"Legacy" layout
|
||||
break;
|
||||
}
|
||||
|
||||
if(*nandType != FIRMWARE_EMUNAND) nandOffset *= ((u32)*nandType - 1);
|
||||
|
||||
if(fatStart >= nandOffset + roundedMinsizes[ISN3DS ? 1 : 0])
|
||||
{
|
||||
//Check for RedNAND
|
||||
if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0)
|
||||
{
|
||||
emuOffset = nandOffset + 1;
|
||||
emuHeader = nandOffset + 1;
|
||||
return;
|
||||
}
|
||||
|
||||
//Check for Gateway EmuNAND
|
||||
else if(i != 2 && !sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0)
|
||||
{
|
||||
emuOffset = nandOffset;
|
||||
emuHeader = nandOffset + nandSize;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(*nandType == FIRMWARE_EMUNAND) break;
|
||||
}
|
||||
|
||||
//Fallback to the first EmuNAND if there's no second/third/fourth one, or to SysNAND if there isn't any
|
||||
if(*nandType != FIRMWARE_EMUNAND)
|
||||
{
|
||||
*nandType = FIRMWARE_EMUNAND;
|
||||
locateEmuNand(nandType);
|
||||
}
|
||||
else *nandType = FIRMWARE_SYSNAND;
|
||||
}
|
||||
|
||||
static inline bool getFreeK9Space(u8 *pos, u32 size, u8 **freeK9Space)
|
||||
{
|
||||
static const u8 pattern[] = {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
|
||||
|
||||
//Looking for the last free space before Process9
|
||||
*freeK9Space = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(*freeK9Space == NULL || (u32)(pos + size - *freeK9Space) < 0x455 + emunandPatchSize ||
|
||||
*(u32 *)(*freeK9Space + 0x455 + emunandPatchSize - 4) != 0xFFFFFFFF) return false;
|
||||
|
||||
*freeK9Space += 0x455;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline u32 getOldSdmmc(u32 *sdmmc, u32 firmVersion)
|
||||
{
|
||||
switch(firmVersion)
|
||||
{
|
||||
case 0x18:
|
||||
*sdmmc = 0x080D91D8;
|
||||
break;
|
||||
case 0x1D:
|
||||
case 0x1F:
|
||||
*sdmmc = 0x080D8CD0;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline u32 getSdmmc(u8 *pos, u32 size, u32 *sdmmc)
|
||||
{
|
||||
//Look for struct code
|
||||
static const u8 pattern[] = {0x21, 0x20, 0x18, 0x20};
|
||||
|
||||
const u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
*sdmmc = *(u32 *)(off + 9) + *(u32 *)(off + 0xD);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline u32 patchNandRw(u8 *pos, u32 size, u32 branchOffset)
|
||||
{
|
||||
//Look for read/write code
|
||||
static const u8 pattern[] = {0x1E, 0x00, 0xC8, 0x05};
|
||||
|
||||
u16 *readOffset = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(readOffset == NULL) return 1;
|
||||
|
||||
readOffset -= 3;
|
||||
|
||||
u16 *writeOffset = (u16 *)memsearch((u8 *)(readOffset + 5), pattern, 0x100, sizeof(pattern));
|
||||
|
||||
if(writeOffset == NULL) return 1;
|
||||
|
||||
writeOffset -= 3;
|
||||
*readOffset = *writeOffset = 0x4C00;
|
||||
readOffset[1] = writeOffset[1] = 0x47A0;
|
||||
((u32 *)writeOffset)[1] = ((u32 *)readOffset)[1] = branchOffset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline u32 patchMpu(u8 *pos, u32 size)
|
||||
{
|
||||
//Look for MPU pattern
|
||||
static const u8 pattern[] = {0x03, 0x00, 0x24, 0x00};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[1] = 0x0036;
|
||||
off[0xC] = off[0x12] = 0x0603;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchEmuNand(u8 *arm9Section, u32 kernel9Size, u8 *process9Offset, u32 process9Size, u8 *kernel9Address, u32 firmVersion)
|
||||
{
|
||||
u8 *freeK9Space;
|
||||
|
||||
if(!getFreeK9Space(arm9Section, kernel9Size, &freeK9Space)) return 1;
|
||||
|
||||
u32 ret = 0;
|
||||
|
||||
//Add the data of the found EmuNAND
|
||||
emunandPatchNandOffset = emuOffset;
|
||||
emunandPatchNcsdHeaderOffset = emuHeader;
|
||||
|
||||
//Find and add the SDMMC struct
|
||||
u32 sdmmc;
|
||||
ret += !ISN3DS && firmVersion < 0x25 ? getOldSdmmc(&sdmmc, firmVersion) : getSdmmc(process9Offset, process9Size, &sdmmc);
|
||||
if(!ret) emunandPatchSdmmcStructPtr = sdmmc;
|
||||
|
||||
//Copy EmuNAND code
|
||||
memcpy(freeK9Space, emunandPatch, emunandPatchSize);
|
||||
|
||||
//Add EmuNAND hooks
|
||||
u32 branchOffset = (u32)(freeK9Space - arm9Section + kernel9Address);
|
||||
ret += patchNandRw(process9Offset, process9Size, branchOffset);
|
||||
|
||||
//Set MPU
|
||||
ret += patchMpu(arm9Section, kernel9Size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
41
arm9/source/emunand.h
Normal file
41
arm9/source/emunand.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code for locating the SDMMC struct by Normmatt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define ROUND_TO_4MB(a) (((a) + 0x2000 - 1) & (~(0x2000 - 1)))
|
||||
|
||||
extern u32 emuOffset,
|
||||
emuHeader;
|
||||
|
||||
void locateEmuNand(FirmwareSource *nandType);
|
||||
u32 patchEmuNand(u8 *arm9Section, u32 kernel9Size, u8 *process9Offset, u32 process9Size, u8 *kernel9Address, u32 firmVersion);
|
||||
197
arm9/source/exceptions.c
Normal file
197
arm9/source/exceptions.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "exceptions.h"
|
||||
#include "fs.h"
|
||||
#include "memory.h"
|
||||
#include "screen.h"
|
||||
#include "draw.h"
|
||||
#include "utils.h"
|
||||
#include "fmt.h"
|
||||
#include "buttons.h"
|
||||
#include "arm9_exception_handlers.h"
|
||||
|
||||
// See https://github.com/LumaTeam/luma3ds_exception_dump_parser
|
||||
|
||||
void installArm9Handlers(void)
|
||||
{
|
||||
vu32 *dstVeneers = (vu32 *)0x08000000;
|
||||
|
||||
for(u32 i = 0; i < 6; i++)
|
||||
{
|
||||
if(arm9ExceptionHandlerAddressTable[i] != 0)
|
||||
{
|
||||
dstVeneers[2 * i] = 0xE51FF004;
|
||||
dstVeneers[2 * i + 1] = arm9ExceptionHandlerAddressTable[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void detectAndProcessExceptionDumps(void)
|
||||
{
|
||||
volatile ExceptionDumpHeader *dumpHeader = (volatile ExceptionDumpHeader *)0x25000000;
|
||||
|
||||
if(dumpHeader->magic[0] != 0xDEADC0DE || dumpHeader->magic[1] != 0xDEADCAFE || (dumpHeader->processor != 9 && dumpHeader->processor != 11)) return;
|
||||
|
||||
const vu32 *regs = (vu32 *)((vu8 *)dumpHeader + sizeof(ExceptionDumpHeader));
|
||||
const vu8 *stackDump = (vu8 *)regs + dumpHeader->registerDumpSize + dumpHeader->codeDumpSize;
|
||||
const vu8 *additionalData = stackDump + dumpHeader->stackDumpSize;
|
||||
|
||||
static const char *handledExceptionNames[] = {
|
||||
"FIQ", "undefined instruction", "prefetch abort", "data abort"
|
||||
},
|
||||
*specialExceptions[] = {
|
||||
"kernel panic", "svcBreak"
|
||||
},
|
||||
*registerNames[] = {
|
||||
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12",
|
||||
"SP", "LR", "PC", "CPSR", "FPEXC"
|
||||
},
|
||||
*faultStatusNames[] = {
|
||||
"Alignment", "Instr.cache maintenance op.",
|
||||
"Ext.Abort on translation - Lv1", "Ext.Abort on translation - Lv2",
|
||||
"Translation - Section", "Translation - Page", "Access bit - Section", "Access bit - Page",
|
||||
"Domain - Section", "Domain - Page", "Permission - Section", "Permission - Page",
|
||||
"Precise External Abort", "Imprecise External Abort", "Debug event"
|
||||
};
|
||||
|
||||
static const u32 faultStatusValues[] = {
|
||||
0b1, 0b100, 0b1100, 0b1110, 0b101, 0b111, 0b11, 0b110, 0b1001, 0b1011, 0b1101,
|
||||
0b1111, 0b1000, 0b10110, 0b10
|
||||
};
|
||||
|
||||
initScreens();
|
||||
|
||||
drawString(true, 10, 10, COLOR_RED, "An exception occurred");
|
||||
u32 posY;
|
||||
if(dumpHeader->processor == 11) posY = drawFormattedString(true, 10, 30, COLOR_WHITE, "Processor: Arm11 (core %u)", dumpHeader->core);
|
||||
else posY = drawString(true, 10, 30, COLOR_WHITE, "Processor: Arm9");
|
||||
|
||||
if(dumpHeader->type == 2)
|
||||
{
|
||||
if((regs[16] & 0x20) == 0 && dumpHeader->codeDumpSize >= 4)
|
||||
{
|
||||
u32 instr = *(vu32 *)(stackDump - 4);
|
||||
if(instr == 0xE12FFF7E)
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s (%s)", handledExceptionNames[dumpHeader->type], specialExceptions[0]);
|
||||
else if(instr == 0xEF00003C)
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s (%s)", handledExceptionNames[dumpHeader->type], specialExceptions[1]);
|
||||
else
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s", handledExceptionNames[dumpHeader->type]);
|
||||
}
|
||||
else if((regs[16] & 0x20) != 0 && dumpHeader->codeDumpSize >= 2)
|
||||
{
|
||||
u16 instr = *(vu16 *)(stackDump - 2);
|
||||
if(instr == 0xDF3C)
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s (%s)", handledExceptionNames[dumpHeader->type], specialExceptions[0]);
|
||||
else
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s", handledExceptionNames[dumpHeader->type]);
|
||||
}
|
||||
else
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s", handledExceptionNames[dumpHeader->type]);
|
||||
}
|
||||
else
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Exception type: %s", handledExceptionNames[dumpHeader->type]);
|
||||
|
||||
if(dumpHeader->processor == 11 && dumpHeader->type >= 2)
|
||||
{
|
||||
u32 xfsr = (dumpHeader->type == 2 ? regs[18] : regs[17]) & 0xF;
|
||||
|
||||
for(u32 i = 0; i < 15; i++)
|
||||
if(xfsr == faultStatusValues[i])
|
||||
{
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Fault status: %s", faultStatusNames[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(dumpHeader->additionalDataSize != 0)
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
|
||||
"Current process: %.8s (%016llX)", (const char *)additionalData, *(vu64 *)(additionalData + 8));
|
||||
posY += SPACING_Y;
|
||||
|
||||
for(u32 i = 0; i < 17; i += 2)
|
||||
{
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "%-7s%08lX", registerNames[i], regs[i]);
|
||||
|
||||
if(i != 16)
|
||||
posY = drawFormattedString(true, 10 + 22 * SPACING_X, posY, COLOR_WHITE, "%-7s%08lX", registerNames[i + 1], regs[i + 1]);
|
||||
else if(dumpHeader->processor == 11)
|
||||
posY = drawFormattedString(true, 10 + 22 * SPACING_X, posY, COLOR_WHITE, "%-7s%08lX", registerNames[i + 1], regs[20]);
|
||||
}
|
||||
|
||||
if(dumpHeader->processor == 11 && dumpHeader->type == 3)
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "%-7s%08lX Access type: %s", "FAR", regs[19], regs[17] & (1u << 11) ? "Write" : "Read");
|
||||
|
||||
posY += SPACING_Y;
|
||||
|
||||
u32 mode = regs[16] & 0xF;
|
||||
if(dumpHeader->type == 3 && (mode == 7 || mode == 11))
|
||||
posY = drawString(true, 10, posY + SPACING_Y, COLOR_YELLOW, "Incorrect dump: failed to dump code and/or stack") + SPACING_Y;
|
||||
|
||||
u32 posYBottom = drawString(false, 10, 10, COLOR_WHITE, "Stack dump:") + SPACING_Y;
|
||||
|
||||
for(u32 line = 0; line < 19 && stackDump < additionalData; line++)
|
||||
{
|
||||
posYBottom = drawFormattedString(false, 10, posYBottom + SPACING_Y, COLOR_WHITE, "%08lX:", regs[13] + 8 * line);
|
||||
|
||||
for(u32 i = 0; i < 8 && stackDump < additionalData; i++, stackDump++)
|
||||
drawFormattedString(false, 10 + 10 * SPACING_X + 3 * i * SPACING_X, posYBottom, COLOR_WHITE, "%02X", *stackDump);
|
||||
}
|
||||
|
||||
static const char *choiceMessage[] = {"Press A to save the crash dump", "Press any other button to shutdown"};
|
||||
|
||||
drawString(true, 10, posY + SPACING_Y, COLOR_WHITE, choiceMessage[0]);
|
||||
drawString(true, 10, posY + SPACING_Y + SPACING_Y , COLOR_WHITE, choiceMessage[1]);
|
||||
|
||||
if(waitInput(false) != BUTTON_A) goto exit;
|
||||
|
||||
drawString(true, 10, posY + SPACING_Y, COLOR_BLACK, choiceMessage[0]);
|
||||
drawString(true, 10, posY + SPACING_Y + SPACING_Y , COLOR_BLACK, choiceMessage[1]);
|
||||
|
||||
char folderPath[32],
|
||||
path[128],
|
||||
fileName[32];
|
||||
|
||||
sprintf(folderPath, "dumps/arm%u", dumpHeader->processor);
|
||||
findDumpFile(folderPath, fileName);
|
||||
sprintf(path, "%s/%s", folderPath, fileName);
|
||||
|
||||
if(fileWrite((void *)dumpHeader, path, dumpHeader->totalSize))
|
||||
{
|
||||
posY = drawString(true, 10, posY + SPACING_Y, COLOR_WHITE, "You can find the dump in the following file:");
|
||||
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE, "%s:/luma/%s", isSdMode ? "SD" : "CTRNAND", path) + SPACING_Y;
|
||||
}
|
||||
else posY = drawString(true, 10, posY + SPACING_Y, COLOR_RED, "Error writing the dump file");
|
||||
|
||||
drawString(true, 10, posY + SPACING_Y, COLOR_WHITE, "Press any button to shutdown");
|
||||
|
||||
waitInput(false);
|
||||
|
||||
exit:
|
||||
memset((void *)dumpHeader, 0, dumpHeader->totalSize);
|
||||
mcuPowerOff();
|
||||
}
|
||||
33
arm9/source/exceptions.h
Normal file
33
arm9/source/exceptions.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void installArm9Handlers(void);
|
||||
u32 installArm11Handlers(u32 *exceptionsPage, u32 stackAddress, u32 codeSetOffset, u32 *dAbtHandler, u32 dAbtHandlerMemAddress);
|
||||
void detectAndProcessExceptionDumps(void);
|
||||
91
loader/source/fatfs/00history.txt → arm9/source/fatfs/00history.txt
Executable file → Normal file
91
loader/source/fatfs/00history.txt → arm9/source/fatfs/00history.txt
Executable file → Normal file
@@ -10,7 +10,7 @@ R0.00 (February 26, 2006)
|
||||
|
||||
R0.01 (April 29, 2006)
|
||||
|
||||
First stable version.
|
||||
The first release.
|
||||
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ R0.10 (October 02, 2013)
|
||||
Improved write throughput of f_puts() and f_printf().
|
||||
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
|
||||
Fixed f_write() can be truncated when the file size is close to 4GB.
|
||||
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code.
|
||||
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error.
|
||||
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ R0.10a (January 15, 2014)
|
||||
R0.10b (May 19, 2014)
|
||||
|
||||
Fixed a hard error in the disk I/O layer can collapse the directory entry.
|
||||
Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN. (appeared at R0.07)
|
||||
Fixed LFN entry is not deleted when delete/rename an object with lossy converted SFN. (appeared at R0.07)
|
||||
|
||||
|
||||
|
||||
@@ -243,3 +243,88 @@ R0.11a (September 05, 2015)
|
||||
Fixed errors in the case conversion teble of Unicode (cc*.c).
|
||||
|
||||
|
||||
|
||||
R0.12 (April 12, 2016)
|
||||
|
||||
Added support for exFAT file system. (_FS_EXFAT)
|
||||
Added f_expand(). (_USE_EXPAND)
|
||||
Changed some members in FINFO structure and behavior of f_readdir().
|
||||
Added an option _USE_CHMOD.
|
||||
Removed an option _WORD_ACCESS.
|
||||
Fixed errors in the case conversion table of Unicode (cc*.c).
|
||||
|
||||
|
||||
|
||||
R0.12a (July 10, 2016)
|
||||
|
||||
Added support for creating exFAT volume with some changes of f_mkfs().
|
||||
Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed.
|
||||
f_forward() is available regardless of _FS_TINY.
|
||||
Fixed f_mkfs() creates wrong volume. (appeared at R0.12)
|
||||
Fixed wrong memory read in create_name(). (appeared at R0.12)
|
||||
Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD.
|
||||
|
||||
|
||||
|
||||
R0.12b (September 04, 2016)
|
||||
|
||||
Made f_rename() be able to rename objects with the same name but case.
|
||||
Fixed an error in the case conversion teble of code page 866. (ff.c)
|
||||
Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12)
|
||||
Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12)
|
||||
Fixed f_mkfs() creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12)
|
||||
Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12)
|
||||
Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12)
|
||||
Fixed some internal errors in f_expand() and f_lseek(). (appeared at R0.12)
|
||||
|
||||
|
||||
|
||||
R0.12c (March 04, 2017)
|
||||
|
||||
Improved write throughput at the fragmented file on the exFAT volume.
|
||||
Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN.
|
||||
Fixed successive f_getfree() can return wrong count on the FAT12/16 volume. (appeared at R0.12)
|
||||
Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c)
|
||||
|
||||
|
||||
|
||||
R0.13 (May 21, 2017)
|
||||
|
||||
Changed heading character of configuration keywords "_" to "FF_".
|
||||
Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead.
|
||||
Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0)
|
||||
Improved cluster allocation time on stretch a deep buried cluster chain.
|
||||
Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3.
|
||||
Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
|
||||
Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
|
||||
Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
|
||||
Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
|
||||
|
||||
|
||||
|
||||
R0.13a (October 14, 2017)
|
||||
|
||||
Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2)
|
||||
Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF).
|
||||
Added dynamic memory allocation option for working buffer of f_mkfs() and f_fdisk().
|
||||
Fixed f_fdisk() and f_mkfs() create the partition table with wrong CHS parameters. (appeared at R0.09)
|
||||
Fixed f_unlink() can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c)
|
||||
Fixed f_setlabel() rejects some valid characters for exFAT volume. (appeared at R0.12)
|
||||
|
||||
|
||||
|
||||
R0.13b (April 07, 2018)
|
||||
|
||||
Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3)
|
||||
Added support for Unix style volume ID. (FF_STR_VOLUME_ID = 2)
|
||||
Fixed accesing any object on the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c)
|
||||
Fixed f_setlabel() does not reject some invalid characters. (appeared at R0.09b)
|
||||
|
||||
|
||||
|
||||
R0.13c (October 14, 2018)
|
||||
Supported stdint.h for C99 and later. (integer.h was included in ff.h)
|
||||
Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
|
||||
Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
|
||||
Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
|
||||
|
||||
21
arm9/source/fatfs/00readme.txt
Normal file
21
arm9/source/fatfs/00readme.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
FatFs Module Source Files R0.13c
|
||||
|
||||
|
||||
FILES
|
||||
|
||||
00readme.txt This file.
|
||||
00history.txt Revision history.
|
||||
ff.c FatFs module.
|
||||
ffconf.h Configuration file of FatFs module.
|
||||
ff.h Common include file for FatFs and application module.
|
||||
diskio.h Common include file for FatFs and disk I/O module.
|
||||
diskio.c An example of glue function to attach existing disk I/O module to FatFs.
|
||||
ffunicode.c Optional Unicode utility functions.
|
||||
ffsystem.c An example of optional O/S related functions.
|
||||
|
||||
|
||||
Low level disk I/O module is not included in this archive because the FatFs
|
||||
module is only a generic file system layer and it does not depend on any specific
|
||||
storage device. You need to provide a low level disk I/O module written to
|
||||
control the storage device that attached to the target system.
|
||||
|
||||
138
arm9/source/fatfs/diskio.c
Normal file
138
arm9/source/fatfs/diskio.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* If a working storage control module is available, it should be */
|
||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||
/* This is an example of glue functions to attach various exsisting */
|
||||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "diskio.h" /* FatFs lower layer API */
|
||||
#include "sdmmc/sdmmc.h"
|
||||
#include "../crypto.h"
|
||||
#include "../i2c.h"
|
||||
|
||||
/* Definitions of physical drive number for each media */
|
||||
#define SDCARD 0
|
||||
#define CTRNAND 1
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (
|
||||
__attribute__((unused))
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
static u32 sdmmcInitResult = 4;
|
||||
|
||||
if(sdmmcInitResult == 4) sdmmcInitResult = sdmmc_sdcard_init();
|
||||
|
||||
return ((pdrv == SDCARD && !(sdmmcInitResult & 2)) ||
|
||||
(pdrv == CTRNAND && !(sdmmcInitResult & 1) && !ctrNandInit())) ? 0 : STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
return ((pdrv == SDCARD && !sdmmc_sdcard_readsectors(sector, count, buff)) ||
|
||||
(pdrv == CTRNAND && !ctrNandRead(sector, count, buff))) ? RES_OK : RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if _USE_WRITE
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
return ((pdrv == SDCARD && (*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) != 0 && !sdmmc_sdcard_writesectors(sector, count, buff)) ||
|
||||
(pdrv == CTRNAND && !ctrNandWrite(sector, count, buff))) ? RES_OK : RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if _USE_IOCTL
|
||||
DRESULT disk_ioctl (
|
||||
__attribute__((unused))
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
__attribute__((unused))
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
return cmd == CTRL_SYNC ? RES_OK : RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
// From GodMode9
|
||||
#define BCDVALID(b) (((b)<=0x99)&&(((b)&0xF)<=0x9)&&((((b)>>4)&0xF)<=0x9))
|
||||
#define BCD2NUM(b) (BCDVALID(b) ? (((b)&0xF)+((((b)>>4)&0xF)*10)) : 0xFF)
|
||||
#define NUM2BCD(n) ((n<99) ? (((n/10)*0x10)|(n%10)) : 0x99)
|
||||
#define DSTIMEGET(bcd,n) (BCD2NUM((bcd)->n))
|
||||
|
||||
// see: http://3dbrew.org/wiki/I2C_Registers#Device_3 (register 30)
|
||||
typedef struct DsTime {
|
||||
u8 bcd_s;
|
||||
u8 bcd_m;
|
||||
u8 bcd_h;
|
||||
u8 weekday;
|
||||
u8 bcd_D;
|
||||
u8 bcd_M;
|
||||
u8 bcd_Y;
|
||||
u8 leap_count;
|
||||
} DsTime;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get current FAT time */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DWORD get_fattime( void ) {
|
||||
DsTime dstime;
|
||||
I2C_readRegBuf(I2C_DEV_MCU, 0x30, (u8 *)&dstime, sizeof(DsTime));
|
||||
DWORD fattime =
|
||||
((DSTIMEGET(&dstime, bcd_s)&0x3F) >> 1 ) |
|
||||
((DSTIMEGET(&dstime, bcd_m)&0x3F) << 5 ) |
|
||||
((DSTIMEGET(&dstime, bcd_h)&0x3F) << 11) |
|
||||
((DSTIMEGET(&dstime, bcd_D)&0x1F) << 16) |
|
||||
((DSTIMEGET(&dstime, bcd_M)&0x0F) << 21) |
|
||||
(((DSTIMEGET(&dstime, bcd_Y)+(2000-1980))&0x7F) << 25);
|
||||
|
||||
return fattime;
|
||||
}
|
||||
@@ -38,6 +38,7 @@ DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
DWORD get_fattime( void ); // not a disk control function, but fits here
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
6554
arm9/source/fatfs/ff.c
Normal file
6554
arm9/source/fatfs/ff.c
Normal file
File diff suppressed because it is too large
Load Diff
405
arm9/source/fatfs/ff.h
Normal file
405
arm9/source/fatfs/ff.h
Normal file
@@ -0,0 +1,405 @@
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem module R0.13c /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 86604 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if FF_DEFINED != FFCONF_DEF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
/* Integer types used for FatFs API */
|
||||
|
||||
#if defined(_WIN32) /* Main development platform */
|
||||
#define FF_INTDEF 2
|
||||
#include <windows.h>
|
||||
typedef unsigned __int64 QWORD;
|
||||
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||
#define FF_INTDEF 2
|
||||
#include <stdint.h>
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||
typedef uint16_t WCHAR; /* 16-bit unsigned integer */
|
||||
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||
#else /* Earlier than C99 */
|
||||
#define FF_INTDEF 1
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||
typedef unsigned short WCHAR; /* 16-bit unsigned integer */
|
||||
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||
#endif
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
#endif
|
||||
|
||||
#if FF_STR_VOLUME_ID
|
||||
#ifndef FF_VOLUME_STRS
|
||||
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#ifndef _INC_TCHAR
|
||||
#define _INC_TCHAR
|
||||
|
||||
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) u8 ## x
|
||||
#define _TEXT(x) u8 ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
|
||||
typedef DWORD TCHAR;
|
||||
#define _T(x) U ## x
|
||||
#define _TEXT(x) U ## x
|
||||
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
|
||||
#error Wrong FF_LFN_UNICODE setting
|
||||
#else /* ANSI/OEM code in SBCS/DBCS */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of file size variables */
|
||||
|
||||
#if FF_FS_EXFAT
|
||||
#if FF_INTDEF != 2
|
||||
#error exFAT feature wants C99 or later
|
||||
#endif
|
||||
typedef QWORD FSIZE_t;
|
||||
#else
|
||||
typedef DWORD FSIZE_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Filesystem object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||
BYTE pdrv; /* Associated physical drive */
|
||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD id; /* Volume mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
WORD csize; /* Cluster size [sectors] */
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if FF_USE_LFN
|
||||
WCHAR* lfnbuf; /* LFN working buffer */
|
||||
#endif
|
||||
#if FF_FS_EXFAT
|
||||
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||
#endif
|
||||
#if FF_FS_REENTRANT
|
||||
FF_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !FF_FS_READONLY
|
||||
DWORD last_clst; /* Last allocated cluster */
|
||||
DWORD free_clst; /* Number of free clusters */
|
||||
#endif
|
||||
#if FF_FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
|
||||
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
|
||||
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
|
||||
#endif
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||
DWORD fsize; /* Size of an FAT [sectors] */
|
||||
DWORD volbase; /* Volume base sector */
|
||||
DWORD fatbase; /* FAT base sector */
|
||||
DWORD dirbase; /* Root directory base sector/cluster */
|
||||
DWORD database; /* Data base sector */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD bitbase; /* Allocation bitmap base sector */
|
||||
#endif
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* Object ID and allocation information (FFOBJID) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the hosting volume of this object */
|
||||
WORD id; /* Hosting volume mount ID */
|
||||
BYTE attr; /* Object attribute */
|
||||
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
|
||||
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
|
||||
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
|
||||
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
|
||||
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
|
||||
#endif
|
||||
#if FF_FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
} FFOBJID;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
|
||||
BYTE flag; /* File status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !FF_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||
#endif
|
||||
#if FF_USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||
#endif
|
||||
#if !FF_FS_TINY
|
||||
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
|
||||
#endif
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier */
|
||||
DWORD dptr; /* Current read/write offset */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector (0:Read operation has terminated) */
|
||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
#if FF_USE_LFN
|
||||
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||
#endif
|
||||
#if FF_USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
/* File information structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
FSIZE_t fsize; /* File size */
|
||||
WORD fdate; /* Modified date */
|
||||
WORD ftime; /* Modified time */
|
||||
BYTE fattrib; /* File attribute */
|
||||
#if FF_USE_LFN
|
||||
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
|
||||
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||
#else
|
||||
TCHAR fname[12 + 1]; /* File name */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->obj.objsize)
|
||||
#define f_rewind(fp) f_lseek((fp), 0)
|
||||
#define f_rewinddir(dp) f_readdir((dp), 0)
|
||||
#define f_rmdir(path) f_unlink(path)
|
||||
#define f_unmount(path) f_mount(0, path, 0)
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||
DWORD get_fattime (void);
|
||||
#endif
|
||||
|
||||
/* LFN support functions */
|
||||
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
||||
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
||||
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
||||
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
||||
#endif
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if FF_FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access mode and open method flags (3rd argument of f_open) */
|
||||
#define FA_READ 0x01
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA_OPEN_APPEND 0x30
|
||||
|
||||
/* Fast seek controls (2nd argument of f_lseek) */
|
||||
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||
|
||||
/* Format options (2nd argument of f_mkfs) */
|
||||
#define FM_FAT 0x01
|
||||
#define FM_FAT32 0x02
|
||||
#define FM_EXFAT 0x04
|
||||
#define FM_ANY 0x07
|
||||
#define FM_SFD 0x08
|
||||
|
||||
/* Filesystem type (FATFS.fs_type) */
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
|
||||
/* File attribute bits for directory entry (FILINFO.fattrib) */
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FF_DEFINED */
|
||||
288
arm9/source/fatfs/ffconf.h
Normal file
288
arm9/source/fatfs/ffconf.h
Normal file
@@ -0,0 +1,288 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs Functional Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FFCONF_DEF 86604 /* Revision ID */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_FS_READONLY 0
|
||||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
||||
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
||||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
||||
/ and optional writing functions as well. */
|
||||
|
||||
|
||||
#define FF_FS_MINIMIZE 0
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: Basic functions are fully enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
|
||||
/ are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
|
||||
#define FF_USE_STRFUNC 0
|
||||
/* This option switches string functions, f_gets(), f_putc(), f_puts() and f_printf().
|
||||
/
|
||||
/ 0: Disable string functions.
|
||||
/ 1: Enable without LF-CRLF conversion.
|
||||
/ 2: Enable with LF-CRLF conversion. */
|
||||
|
||||
|
||||
#define FF_USE_FIND 1
|
||||
/* This option switches filtered directory read functions, f_findfirst() and
|
||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
||||
|
||||
|
||||
#define FF_USE_MKFS 0
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FASTSEEK 0
|
||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_EXPAND 0
|
||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_CHMOD 0
|
||||
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
|
||||
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
|
||||
|
||||
|
||||
#define FF_USE_LABEL 0
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_CODE_PAGE 437
|
||||
/* This option specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect code page setting can cause a file open failure.
|
||||
/
|
||||
/ 437 - U.S.
|
||||
/ 720 - Arabic
|
||||
/ 737 - Greek
|
||||
/ 771 - KBL
|
||||
/ 775 - Baltic
|
||||
/ 850 - Latin 1
|
||||
/ 852 - Latin 2
|
||||
/ 855 - Cyrillic
|
||||
/ 857 - Turkish
|
||||
/ 860 - Portuguese
|
||||
/ 861 - Icelandic
|
||||
/ 862 - Hebrew
|
||||
/ 863 - Canadian French
|
||||
/ 864 - Arabic
|
||||
/ 865 - Nordic
|
||||
/ 866 - Russian
|
||||
/ 869 - Greek 2
|
||||
/ 932 - Japanese (DBCS)
|
||||
/ 936 - Simplified Chinese (DBCS)
|
||||
/ 949 - Korean (DBCS)
|
||||
/ 950 - Traditional Chinese (DBCS)
|
||||
/ 0 - Include all code pages above and configured by f_setcp()
|
||||
*/
|
||||
|
||||
|
||||
#define FF_USE_LFN 2
|
||||
#define FF_MAX_LFN 255
|
||||
/* The FF_USE_LFN switches the support for LFN (long file name).
|
||||
/
|
||||
/ 0: Disable LFN. FF_MAX_LFN has no effect.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
|
||||
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
||||
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
||||
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
||||
/ be in range of 12 to 255. It is recommended to be set 255 to fully support LFN
|
||||
/ specification.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
||||
|
||||
|
||||
#define FF_LFN_UNICODE 2
|
||||
/* This option switches the character encoding on the API when LFN is enabled.
|
||||
/
|
||||
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
||||
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
|
||||
/ 2: Unicode in UTF-8 (TCHAR = char)
|
||||
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
|
||||
/
|
||||
/ Also behavior of string I/O functions will be affected by this option.
|
||||
/ When LFN is not enabled, this option has no effect. */
|
||||
|
||||
|
||||
#define FF_LFN_BUF 255
|
||||
#define FF_SFN_BUF 12
|
||||
/* This set of options defines size of file name members in the FILINFO structure
|
||||
/ which is used to read out directory items. These values should be suffcient for
|
||||
/ the file names to read. The maximum possible length of the read file name depends
|
||||
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
||||
|
||||
|
||||
#define FF_STRF_ENCODE 3
|
||||
/* When FF_LFN_UNICODE >= 1 with LFN enabled, string I/O functions, f_gets(),
|
||||
/ f_putc(), f_puts and f_printf() convert the character encoding in it.
|
||||
/ This option selects assumption of character encoding ON THE FILE to be
|
||||
/ read/written via those functions.
|
||||
/
|
||||
/ 0: ANSI/OEM in current CP
|
||||
/ 1: Unicode in UTF-16LE
|
||||
/ 2: Unicode in UTF-16BE
|
||||
/ 3: Unicode in UTF-8
|
||||
*/
|
||||
|
||||
|
||||
#define FF_FS_RPATH 1
|
||||
/* This option configures support for relative path.
|
||||
/
|
||||
/ 0: Disable relative path and remove related functions.
|
||||
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_VOLUMES 2
|
||||
/* Number of volumes (logical drives) to be used. (1-10) */
|
||||
|
||||
|
||||
#define FF_STR_VOLUME_ID 0
|
||||
#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
|
||||
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
||||
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
||||
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
|
||||
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
|
||||
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
|
||||
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
|
||||
/ not defined, a user defined volume string table needs to be defined as:
|
||||
/
|
||||
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
|
||||
*/
|
||||
|
||||
|
||||
#define FF_MULTI_PARTITION 0
|
||||
/* This option switches support for multiple volumes on the physical drive.
|
||||
/ By default (0), each logical drive number is bound to the same physical drive
|
||||
/ number and only an FAT volume found on the physical drive will be mounted.
|
||||
/ When this function is enabled (1), each logical drive number can be bound to
|
||||
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
|
||||
/ funciton will be available. */
|
||||
|
||||
|
||||
#define FF_MIN_SS 512
|
||||
#define FF_MAX_SS 512
|
||||
/* This set of options configures the range of sector size to be supported. (512,
|
||||
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
|
||||
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
|
||||
/ for variable sector size mode and disk_ioctl() function needs to implement
|
||||
/ GET_SECTOR_SIZE command. */
|
||||
|
||||
|
||||
#define FF_USE_TRIM 0
|
||||
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
|
||||
#define FF_FS_NOFSINFO 0
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_FS_TINY 0
|
||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
|
||||
/ Instead of private sector buffer eliminated from the file object, common sector
|
||||
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
|
||||
|
||||
|
||||
#define FF_FS_EXFAT 0
|
||||
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
||||
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
|
||||
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
||||
|
||||
|
||||
#define FF_FS_NORTC 0
|
||||
#define FF_NORTC_MON 1
|
||||
#define FF_NORTC_MDAY 1
|
||||
#define FF_NORTC_YEAR 2019
|
||||
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
|
||||
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
||||
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
||||
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
|
||||
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
||||
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
||||
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
|
||||
|
||||
|
||||
#define FF_FS_LOCK 0
|
||||
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
|
||||
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
|
||||
/ is 1.
|
||||
/
|
||||
/ 0: Disable file lock function. To avoid volume corruption, application program
|
||||
/ should avoid illegal open, remove and rename to the open objects.
|
||||
/ >0: Enable file lock function. The value defines how many files/sub-directories
|
||||
/ can be opened simultaneously under file lock control. Note that the file
|
||||
/ lock control is independent of re-entrancy. */
|
||||
|
||||
|
||||
/* #include <somertos.h> // O/S definitions */
|
||||
#define FF_FS_REENTRANT 0
|
||||
#define FF_FS_TIMEOUT 1000
|
||||
#define FF_SYNC_t HANDLE
|
||||
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
|
||||
/ module itself. Note that regardless of this option, file access to different
|
||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||
/ to the same volume is under control of this function.
|
||||
/
|
||||
/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function, must be added to the project. Samples are available in
|
||||
/ option/syscall.c.
|
||||
/
|
||||
/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
|
||||
/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
||||
/ included somewhere in the scope of ff.h. */
|
||||
|
||||
|
||||
|
||||
/*--- End of configuration options ---*/
|
||||
170
arm9/source/fatfs/ffsystem.c
Normal file
170
arm9/source/fatfs/ffsystem.c
Normal file
@@ -0,0 +1,170 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sample Code of OS Dependent Functions for FatFs */
|
||||
/* (C)ChaN, 2018 */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Free a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
|
||||
)
|
||||
{
|
||||
free(mblock); /* Free the memory block with POSIX API */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to create a new
|
||||
/ synchronization object for the volume, such as semaphore and mutex.
|
||||
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
|
||||
|
||||
|
||||
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||
BYTE vol, /* Corresponding volume (logical drive number) */
|
||||
FF_SYNC_t* sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
*sobj = CreateMutex(NULL, FALSE, NULL);
|
||||
return (int)(*sobj != INVALID_HANDLE_VALUE);
|
||||
|
||||
/* uITRON */
|
||||
// T_CSEM csem = {TA_TPRI,1,1};
|
||||
// *sobj = acre_sem(&csem);
|
||||
// return (int)(*sobj > 0);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// *sobj = OSMutexCreate(0, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// *sobj = xSemaphoreCreateMutex();
|
||||
// return (int)(*sobj != NULL);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// *sobj = osMutexCreate(&Mutex[vol]);
|
||||
// return (int)(*sobj != NULL);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
|
||||
/ the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
|
||||
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)CloseHandle(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(del_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// vSemaphoreDelete(sobj);
|
||||
// return 1;
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexDelete(sobj) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
|
||||
FF_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(wai_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
FF_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
ReleaseMutex(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// sig_sem(sobj);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OSMutexPost(sobj);
|
||||
|
||||
/* FreeRTOS */
|
||||
// xSemaphoreGive(sobj);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// osMutexRelease(sobj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
15597
arm9/source/fatfs/ffunicode.c
Normal file
15597
arm9/source/fatfs/ffunicode.c
Normal file
File diff suppressed because it is too large
Load Diff
19
source/fatfs/integer.h → arm9/source/fatfs/integer.h
Executable file → Normal file
19
source/fatfs/integer.h → arm9/source/fatfs/integer.h
Executable file → Normal file
@@ -2,16 +2,22 @@
|
||||
/* Integer type definitions for FatFs module */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
#ifndef _FF_INTEGER
|
||||
#define _FF_INTEGER
|
||||
#ifndef FF_INTEGER
|
||||
#define FF_INTEGER
|
||||
|
||||
#ifdef _WIN32 /* Development platform */
|
||||
#ifdef _WIN32 /* FatFs development platform */
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
typedef unsigned __int64 QWORD;
|
||||
|
||||
|
||||
#else /* Embedded platform */
|
||||
|
||||
/* These types MUST be 16-bit or 32-bit */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* This type MUST be 8-bit */
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
@@ -20,14 +26,13 @@ typedef short SHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types MUST be 16-bit or 32-bit */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types MUST be 32-bit */
|
||||
typedef long LONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
|
||||
typedef unsigned long long QWORD;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
5
arm9/source/fatfs/sdmmc/delay.h
Normal file
5
arm9/source/fatfs/sdmmc/delay.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../types.h"
|
||||
|
||||
void waitcycles(u32 us);
|
||||
16
arm9/source/fatfs/sdmmc/delay.s
Normal file
16
arm9/source/fatfs/sdmmc/delay.s
Normal file
@@ -0,0 +1,16 @@
|
||||
.text
|
||||
.arm
|
||||
.align 4
|
||||
|
||||
.global waitcycles
|
||||
.type waitcycles, %function
|
||||
waitcycles:
|
||||
push {r0-r2, lr}
|
||||
str r0, [sp, #4]
|
||||
waitcycles_loop:
|
||||
ldr r3, [sp, #4]
|
||||
subs r2, r3, #1
|
||||
str r2, [sp, #4]
|
||||
cmp r3, #0
|
||||
bne waitcycles_loop
|
||||
pop {r0-r2, pc}
|
||||
482
arm9/source/fatfs/sdmmc/sdmmc.c
Normal file
482
arm9/source/fatfs/sdmmc/sdmmc.c
Normal file
@@ -0,0 +1,482 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright (c) 2014-2015, Normmatt
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms
|
||||
* of the GNU General Public License Version 2, as described below:
|
||||
*
|
||||
* This file is free software: you may copy, redistribute and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This file 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 http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "sdmmc.h"
|
||||
#include "delay.h"
|
||||
|
||||
static struct mmcdevice handleNAND;
|
||||
static struct mmcdevice handleSD;
|
||||
|
||||
static inline u16 sdmmc_read16(u16 reg)
|
||||
{
|
||||
return *(vu16 *)(SDMMC_BASE + reg);
|
||||
}
|
||||
|
||||
static inline void sdmmc_write16(u16 reg, u16 val)
|
||||
{
|
||||
*(vu16 *)(SDMMC_BASE + reg) = val;
|
||||
}
|
||||
|
||||
static inline u32 sdmmc_read32(u16 reg)
|
||||
{
|
||||
return *(vu32 *)(SDMMC_BASE + reg);
|
||||
}
|
||||
|
||||
static inline void sdmmc_write32(u16 reg, u32 val)
|
||||
{
|
||||
*(vu32 *)(SDMMC_BASE + reg) = val;
|
||||
}
|
||||
|
||||
static inline void sdmmc_mask16(u16 reg, const u16 clear, const u16 set)
|
||||
{
|
||||
u16 val = sdmmc_read16(reg);
|
||||
val &= ~clear;
|
||||
val |= set;
|
||||
sdmmc_write16(reg, val);
|
||||
}
|
||||
|
||||
static inline void setckl(u32 data)
|
||||
{
|
||||
sdmmc_mask16(REG_SDCLKCTL, 0x100, 0);
|
||||
sdmmc_mask16(REG_SDCLKCTL, 0x2FF, data & 0x2FF);
|
||||
sdmmc_mask16(REG_SDCLKCTL, 0x0, 0x100);
|
||||
}
|
||||
|
||||
mmcdevice *getMMCDevice(int drive)
|
||||
{
|
||||
if(drive == 0) return &handleNAND;
|
||||
return &handleSD;
|
||||
}
|
||||
|
||||
static int geterror(struct mmcdevice *ctx)
|
||||
{
|
||||
return (int)((ctx->error << 29) >> 31);
|
||||
}
|
||||
|
||||
static void inittarget(struct mmcdevice *ctx)
|
||||
{
|
||||
sdmmc_mask16(REG_SDPORTSEL, 0x3, (u16)ctx->devicenumber);
|
||||
setckl(ctx->clk);
|
||||
if(ctx->SDOPT == 0) sdmmc_mask16(REG_SDOPT, 0, 0x8000);
|
||||
else sdmmc_mask16(REG_SDOPT, 0x8000, 0);
|
||||
}
|
||||
|
||||
static void __attribute__((noinline)) sdmmc_send_command(struct mmcdevice *ctx, u32 cmd, u32 args)
|
||||
{
|
||||
u32 getSDRESP = (cmd << 15) >> 31;
|
||||
u16 flags = (cmd << 15) >> 31;
|
||||
const int readdata = cmd & 0x20000;
|
||||
const int writedata = cmd & 0x40000;
|
||||
|
||||
if(readdata || writedata)
|
||||
flags |= TMIO_STAT0_DATAEND;
|
||||
|
||||
ctx->error = 0;
|
||||
while((sdmmc_read16(REG_SDSTATUS1) & TMIO_STAT1_CMD_BUSY)); //mmc working?
|
||||
sdmmc_write16(REG_SDIRMASK0, 0);
|
||||
sdmmc_write16(REG_SDIRMASK1, 0);
|
||||
sdmmc_write16(REG_SDSTATUS0, 0);
|
||||
sdmmc_write16(REG_SDSTATUS1, 0);
|
||||
sdmmc_mask16(REG_DATACTL32, 0x1800, 0);
|
||||
sdmmc_write16(REG_SDCMDARG0, args & 0xFFFF);
|
||||
sdmmc_write16(REG_SDCMDARG1, args >> 16);
|
||||
sdmmc_write16(REG_SDCMD, cmd & 0xFFFF);
|
||||
|
||||
u32 size = ctx->size;
|
||||
u8 *rDataPtr = ctx->rData;
|
||||
const u8 *tDataPtr = ctx->tData;
|
||||
|
||||
bool rUseBuf = rDataPtr != NULL;
|
||||
bool tUseBuf = tDataPtr != NULL;
|
||||
|
||||
u16 status0 = 0;
|
||||
while(true)
|
||||
{
|
||||
vu16 status1 = sdmmc_read16(REG_SDSTATUS1);
|
||||
vu16 ctl32 = sdmmc_read16(REG_DATACTL32);
|
||||
if((ctl32 & 0x100))
|
||||
{
|
||||
if(readdata)
|
||||
{
|
||||
if(rUseBuf)
|
||||
{
|
||||
sdmmc_mask16(REG_SDSTATUS1, TMIO_STAT1_RXRDY, 0);
|
||||
if(size > 0x1FF)
|
||||
{
|
||||
//Gabriel Marcano: This implementation doesn't assume alignment.
|
||||
//I've removed the alignment check doen with former rUseBuf32 as a result
|
||||
for(int i = 0; i < 0x200; i += 4)
|
||||
{
|
||||
u32 data = sdmmc_read32(REG_SDFIFO32);
|
||||
*rDataPtr++ = data;
|
||||
*rDataPtr++ = data >> 8;
|
||||
*rDataPtr++ = data >> 16;
|
||||
*rDataPtr++ = data >> 24;
|
||||
}
|
||||
size -= 0x200;
|
||||
}
|
||||
}
|
||||
|
||||
sdmmc_mask16(REG_DATACTL32, 0x800, 0);
|
||||
}
|
||||
}
|
||||
if(!(ctl32 & 0x200))
|
||||
{
|
||||
if(writedata)
|
||||
{
|
||||
if(tUseBuf)
|
||||
{
|
||||
sdmmc_mask16(REG_SDSTATUS1, TMIO_STAT1_TXRQ, 0);
|
||||
if(size > 0x1FF)
|
||||
{
|
||||
for(int i = 0; i < 0x200; i += 4)
|
||||
{
|
||||
u32 data = *tDataPtr++;
|
||||
data |= (u32)*tDataPtr++ << 8;
|
||||
data |= (u32)*tDataPtr++ << 16;
|
||||
data |= (u32)*tDataPtr++ << 24;
|
||||
sdmmc_write32(REG_SDFIFO32, data);
|
||||
}
|
||||
size -= 0x200;
|
||||
}
|
||||
}
|
||||
|
||||
sdmmc_mask16(REG_DATACTL32, 0x1000, 0);
|
||||
}
|
||||
}
|
||||
if(status1 & TMIO_MASK_GW)
|
||||
{
|
||||
ctx->error |= 4;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!(status1 & TMIO_STAT1_CMD_BUSY))
|
||||
{
|
||||
status0 = sdmmc_read16(REG_SDSTATUS0);
|
||||
if(sdmmc_read16(REG_SDSTATUS0) & TMIO_STAT0_CMDRESPEND)
|
||||
{
|
||||
ctx->error |= 0x1;
|
||||
}
|
||||
if(status0 & TMIO_STAT0_DATAEND)
|
||||
{
|
||||
ctx->error |= 0x2;
|
||||
}
|
||||
|
||||
if((status0 & flags) == flags)
|
||||
break;
|
||||
}
|
||||
}
|
||||
ctx->stat0 = sdmmc_read16(REG_SDSTATUS0);
|
||||
ctx->stat1 = sdmmc_read16(REG_SDSTATUS1);
|
||||
sdmmc_write16(REG_SDSTATUS0, 0);
|
||||
sdmmc_write16(REG_SDSTATUS1, 0);
|
||||
|
||||
if(getSDRESP != 0)
|
||||
{
|
||||
ctx->ret[0] = (u32)(sdmmc_read16(REG_SDRESP0) | (sdmmc_read16(REG_SDRESP1) << 16));
|
||||
ctx->ret[1] = (u32)(sdmmc_read16(REG_SDRESP2) | (sdmmc_read16(REG_SDRESP3) << 16));
|
||||
ctx->ret[2] = (u32)(sdmmc_read16(REG_SDRESP4) | (sdmmc_read16(REG_SDRESP5) << 16));
|
||||
ctx->ret[3] = (u32)(sdmmc_read16(REG_SDRESP6) | (sdmmc_read16(REG_SDRESP7) << 16));
|
||||
}
|
||||
}
|
||||
|
||||
int __attribute__((noinline)) sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, const u8 *in)
|
||||
{
|
||||
if(handleSD.isSDHC == 0) sector_no <<= 9;
|
||||
inittarget(&handleSD);
|
||||
sdmmc_write16(REG_SDSTOP, 0x100);
|
||||
sdmmc_write16(REG_SDBLKCOUNT32, numsectors);
|
||||
sdmmc_write16(REG_SDBLKLEN32, 0x200);
|
||||
sdmmc_write16(REG_SDBLKCOUNT, numsectors);
|
||||
handleSD.tData = in;
|
||||
handleSD.size = numsectors << 9;
|
||||
sdmmc_send_command(&handleSD, 0x52C19, sector_no);
|
||||
return geterror(&handleSD);
|
||||
}
|
||||
|
||||
int __attribute__((noinline)) sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, u8 *out)
|
||||
{
|
||||
if(handleSD.isSDHC == 0) sector_no <<= 9;
|
||||
inittarget(&handleSD);
|
||||
sdmmc_write16(REG_SDSTOP, 0x100);
|
||||
sdmmc_write16(REG_SDBLKCOUNT32, numsectors);
|
||||
sdmmc_write16(REG_SDBLKLEN32, 0x200);
|
||||
sdmmc_write16(REG_SDBLKCOUNT, numsectors);
|
||||
handleSD.rData = out;
|
||||
handleSD.size = numsectors << 9;
|
||||
sdmmc_send_command(&handleSD, 0x33C12, sector_no);
|
||||
return geterror(&handleSD);
|
||||
}
|
||||
|
||||
int __attribute__((noinline)) sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, u8 *out)
|
||||
{
|
||||
if(handleNAND.isSDHC == 0) sector_no <<= 9;
|
||||
inittarget(&handleNAND);
|
||||
sdmmc_write16(REG_SDSTOP, 0x100);
|
||||
sdmmc_write16(REG_SDBLKCOUNT32, numsectors);
|
||||
sdmmc_write16(REG_SDBLKLEN32, 0x200);
|
||||
sdmmc_write16(REG_SDBLKCOUNT, numsectors);
|
||||
handleNAND.rData = out;
|
||||
handleNAND.size = numsectors << 9;
|
||||
sdmmc_send_command(&handleNAND, 0x33C12, sector_no);
|
||||
inittarget(&handleSD);
|
||||
return geterror(&handleNAND);
|
||||
}
|
||||
|
||||
int __attribute__((noinline)) sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, const u8 *in) //experimental
|
||||
{
|
||||
if(handleNAND.isSDHC == 0) sector_no <<= 9;
|
||||
inittarget(&handleNAND);
|
||||
sdmmc_write16(REG_SDSTOP, 0x100);
|
||||
sdmmc_write16(REG_SDBLKCOUNT32, numsectors);
|
||||
sdmmc_write16(REG_SDBLKLEN32, 0x200);
|
||||
sdmmc_write16(REG_SDBLKCOUNT, numsectors);
|
||||
handleNAND.tData = in;
|
||||
handleNAND.size = numsectors << 9;
|
||||
sdmmc_send_command(&handleNAND, 0x52C19, sector_no);
|
||||
inittarget(&handleSD);
|
||||
return geterror(&handleNAND);
|
||||
}
|
||||
|
||||
static u32 calcSDSize(u8 *csd, int type)
|
||||
{
|
||||
u32 result = 0;
|
||||
if(type == -1) type = csd[14] >> 6;
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
u32 block_len = csd[9] & 0xF;
|
||||
block_len = 1u << block_len;
|
||||
u32 mult = (u32)((csd[4] >> 7) | ((csd[5] & 3) << 1));
|
||||
mult = 1u << (mult + 2);
|
||||
result = csd[8] & 3;
|
||||
result = (result << 8) | csd[7];
|
||||
result = (result << 2) | (csd[6] >> 6);
|
||||
result = (result + 1) * mult * block_len / 512;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
result = csd[7] & 0x3F;
|
||||
result = (result << 8) | csd[6];
|
||||
result = (result << 8) | csd[5];
|
||||
result = (result + 1) * 1024;
|
||||
break;
|
||||
default:
|
||||
break; //Do nothing otherwise FIXME perhaps return some error?
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void InitSD()
|
||||
{
|
||||
*(vu32 *)0x10000020 = 0; //InitFS stuff
|
||||
*(vu32 *)0x10000020 = 0x200; //InitFS stuff
|
||||
*(vu16 *)0x10006100 &= 0xF7FFu; //SDDATACTL32
|
||||
*(vu16 *)0x10006100 &= 0xEFFFu; //SDDATACTL32
|
||||
*(vu16 *)0x10006100 |= 0x402u; //SDDATACTL32
|
||||
*(vu16 *)0x100060D8 = (*(vu16 *)0x100060D8 & 0xFFDD) | 2;
|
||||
*(vu16 *)0x10006100 &= 0xFFFFu; //SDDATACTL32
|
||||
*(vu16 *)0x100060D8 &= 0xFFDFu; //SDDATACTL
|
||||
*(vu16 *)0x10006104 = 512; //SDBLKLEN32
|
||||
*(vu16 *)0x10006108 = 1; //SDBLKCOUNT32
|
||||
*(vu16 *)0x100060E0 &= 0xFFFEu; //SDRESET
|
||||
*(vu16 *)0x100060E0 |= 1u; //SDRESET
|
||||
*(vu16 *)0x10006020 |= TMIO_MASK_ALL; //SDIR_MASK0
|
||||
*(vu16 *)0x10006022 |= TMIO_MASK_ALL>>16; //SDIR_MASK1
|
||||
*(vu16 *)0x100060FC |= 0xDBu; //SDCTL_RESERVED7
|
||||
*(vu16 *)0x100060FE |= 0xDBu; //SDCTL_RESERVED8
|
||||
*(vu16 *)0x10006002 &= 0xFFFCu; //SDPORTSEL
|
||||
*(vu16 *)0x10006024 = 0x20;
|
||||
*(vu16 *)0x10006028 = 0x40EE;
|
||||
*(vu16 *)0x10006002 &= 0xFFFCu; ////SDPORTSEL
|
||||
*(vu16 *)0x10006026 = 512; //SDBLKLEN
|
||||
*(vu16 *)0x10006008 = 0; //SDSTOP
|
||||
}
|
||||
|
||||
static int Nand_Init()
|
||||
{
|
||||
//NAND
|
||||
handleNAND.isSDHC = 0;
|
||||
handleNAND.SDOPT = 0;
|
||||
handleNAND.res = 0;
|
||||
handleNAND.initarg = 1;
|
||||
handleNAND.clk = 0x80;
|
||||
handleNAND.devicenumber = 1;
|
||||
|
||||
inittarget(&handleNAND);
|
||||
waitcycles(0xF000);
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0, 0);
|
||||
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
sdmmc_send_command(&handleNAND, 0x10701, 0x100000);
|
||||
}
|
||||
while(!(handleNAND.error & 1));
|
||||
}
|
||||
while((handleNAND.ret[0] & 0x80000000) == 0);
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10602, 0x0);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10403, handleNAND.initarg << 0x10);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10609, handleNAND.initarg << 0x10);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
handleNAND.total_size = calcSDSize((u8*)&handleNAND.ret[0], 0);
|
||||
handleNAND.clk = 1;
|
||||
setckl(1);
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10407, handleNAND.initarg << 0x10);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
handleNAND.SDOPT = 1;
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10506, 0x3B70100);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10506, 0x3B90100);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x1040D, handleNAND.initarg << 0x10);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
sdmmc_send_command(&handleNAND, 0x10410, 0x200);
|
||||
if((handleNAND.error & 0x4)) return -1;
|
||||
|
||||
handleNAND.clk |= 0x200;
|
||||
|
||||
inittarget(&handleSD);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SD_Init()
|
||||
{
|
||||
//SD
|
||||
handleSD.isSDHC = 0;
|
||||
handleSD.SDOPT = 0;
|
||||
handleSD.res = 0;
|
||||
handleSD.initarg = 0;
|
||||
handleSD.clk = 0x80;
|
||||
handleSD.devicenumber = 0;
|
||||
|
||||
inittarget(&handleSD);
|
||||
|
||||
waitcycles(1u << 22); //Card needs a little bit of time to be detected, it seems FIXME test again to see what a good number is for the delay
|
||||
|
||||
//If not inserted
|
||||
if(!(*((vu16 *)(SDMMC_BASE + REG_SDSTATUS0)) & TMIO_STAT0_SIGSTATE)) return 5;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0, 0);
|
||||
sdmmc_send_command(&handleSD, 0x10408, 0x1AA);
|
||||
u32 temp = (handleSD.error & 0x1) << 0x1E;
|
||||
|
||||
u32 temp2 = 0;
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
sdmmc_send_command(&handleSD, 0x10437, handleSD.initarg << 0x10);
|
||||
sdmmc_send_command(&handleSD, 0x10769, 0x00FF8000 | temp);
|
||||
temp2 = 1;
|
||||
}
|
||||
while(!(handleSD.error & 1));
|
||||
}
|
||||
while((handleSD.ret[0] & 0x80000000) == 0);
|
||||
|
||||
if(!((handleSD.ret[0] >> 30) & 1) || !temp)
|
||||
temp2 = 0;
|
||||
|
||||
handleSD.isSDHC = temp2;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x10602, 0);
|
||||
if((handleSD.error & 0x4)) return -1;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x10403, 0);
|
||||
if((handleSD.error & 0x4)) return -2;
|
||||
handleSD.initarg = handleSD.ret[0] >> 0x10;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x10609, handleSD.initarg << 0x10);
|
||||
if((handleSD.error & 0x4)) return -3;
|
||||
|
||||
handleSD.total_size = calcSDSize((u8*)&handleSD.ret[0], -1);
|
||||
handleSD.clk = 1;
|
||||
setckl(1);
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x10507, handleSD.initarg << 0x10);
|
||||
if((handleSD.error & 0x4)) return -4;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x10437, handleSD.initarg << 0x10);
|
||||
if((handleSD.error & 0x4)) return -5;
|
||||
|
||||
handleSD.SDOPT = 1;
|
||||
sdmmc_send_command(&handleSD, 0x10446, 0x2);
|
||||
if((handleSD.error & 0x4)) return -6;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x1040D, handleSD.initarg << 0x10);
|
||||
if((handleSD.error & 0x4)) return -7;
|
||||
|
||||
sdmmc_send_command(&handleSD, 0x10410, 0x200);
|
||||
if((handleSD.error & 0x4)) return -8;
|
||||
handleSD.clk |= 0x200;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdmmc_get_cid(bool isNand, u32 *info)
|
||||
{
|
||||
struct mmcdevice *device = isNand ? &handleNAND : &handleSD;
|
||||
|
||||
inittarget(device);
|
||||
|
||||
// use cmd7 to put sd card in standby mode
|
||||
// CMD7
|
||||
sdmmc_send_command(device, 0x10507, 0);
|
||||
|
||||
// get sd card info
|
||||
// use cmd10 to read CID
|
||||
sdmmc_send_command(device, 0x1060A, device->initarg << 0x10);
|
||||
|
||||
for(int i = 0; i < 4; ++i)
|
||||
info[i] = device->ret[i];
|
||||
|
||||
// put sd card back to transfer mode
|
||||
// CMD7
|
||||
sdmmc_send_command(device, 0x10507, device->initarg << 0x10);
|
||||
}
|
||||
|
||||
u32 sdmmc_sdcard_init()
|
||||
{
|
||||
u32 ret = 0;
|
||||
InitSD();
|
||||
if(Nand_Init() != 0) ret |= 1;
|
||||
if(SD_Init() != 0) ret |= 2;
|
||||
return ret;
|
||||
}
|
||||
100
arm9/source/fatfs/sdmmc/sdmmc.h
Normal file
100
arm9/source/fatfs/sdmmc/sdmmc.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../types.h"
|
||||
|
||||
#define SDMMC_BASE 0x10006000
|
||||
|
||||
#define REG_SDCMD 0x00
|
||||
#define REG_SDPORTSEL 0x02
|
||||
#define REG_SDCMDARG 0x04
|
||||
#define REG_SDCMDARG0 0x04
|
||||
#define REG_SDCMDARG1 0x06
|
||||
#define REG_SDSTOP 0x08
|
||||
#define REG_SDBLKCOUNT 0x0A
|
||||
|
||||
#define REG_SDRESP0 0x0C
|
||||
#define REG_SDRESP1 0x0E
|
||||
#define REG_SDRESP2 0x10
|
||||
#define REG_SDRESP3 0x12
|
||||
#define REG_SDRESP4 0x14
|
||||
#define REG_SDRESP5 0x16
|
||||
#define REG_SDRESP6 0x18
|
||||
#define REG_SDRESP7 0x1A
|
||||
|
||||
#define REG_SDSTATUS0 0x1C
|
||||
#define REG_SDSTATUS1 0x1E
|
||||
|
||||
#define REG_SDIRMASK0 0x20
|
||||
#define REG_SDIRMASK1 0x22
|
||||
#define REG_SDCLKCTL 0x24
|
||||
|
||||
#define REG_SDBLKLEN 0x26
|
||||
#define REG_SDOPT 0x28
|
||||
#define REG_SDFIFO 0x30
|
||||
|
||||
#define REG_DATACTL 0xD8
|
||||
#define REG_SDRESET 0xE0
|
||||
#define REG_SDPROTECTED 0xF6 //bit 0 determines if sd is protected or not?
|
||||
|
||||
#define REG_DATACTL32 0x100
|
||||
#define REG_SDBLKLEN32 0x104
|
||||
#define REG_SDBLKCOUNT32 0x108
|
||||
#define REG_SDFIFO32 0x10C
|
||||
|
||||
#define REG_CLK_AND_WAIT_CTL 0x138
|
||||
#define REG_RESET_SDIO 0x1E0
|
||||
|
||||
#define TMIO_STAT0_CMDRESPEND 0x0001
|
||||
#define TMIO_STAT0_DATAEND 0x0004
|
||||
#define TMIO_STAT0_CARD_REMOVE 0x0008
|
||||
#define TMIO_STAT0_CARD_INSERT 0x0010
|
||||
#define TMIO_STAT0_SIGSTATE 0x0020
|
||||
#define TMIO_STAT0_WRPROTECT 0x0080
|
||||
#define TMIO_STAT0_CARD_REMOVE_A 0x0100
|
||||
#define TMIO_STAT0_CARD_INSERT_A 0x0200
|
||||
#define TMIO_STAT0_SIGSTATE_A 0x0400
|
||||
#define TMIO_STAT1_CMD_IDX_ERR 0x0001
|
||||
#define TMIO_STAT1_CRCFAIL 0x0002
|
||||
#define TMIO_STAT1_STOPBIT_ERR 0x0004
|
||||
#define TMIO_STAT1_DATATIMEOUT 0x0008
|
||||
#define TMIO_STAT1_RXOVERFLOW 0x0010
|
||||
#define TMIO_STAT1_TXUNDERRUN 0x0020
|
||||
#define TMIO_STAT1_CMDTIMEOUT 0x0040
|
||||
#define TMIO_STAT1_RXRDY 0x0100
|
||||
#define TMIO_STAT1_TXRQ 0x0200
|
||||
#define TMIO_STAT1_ILL_FUNC 0x2000
|
||||
#define TMIO_STAT1_CMD_BUSY 0x4000
|
||||
#define TMIO_STAT1_ILL_ACCESS 0x8000
|
||||
|
||||
#define TMIO_MASK_ALL 0x837F031D
|
||||
|
||||
#define TMIO_MASK_GW (TMIO_STAT1_ILL_ACCESS | TMIO_STAT1_CMDTIMEOUT | TMIO_STAT1_TXUNDERRUN | TMIO_STAT1_RXOVERFLOW | \
|
||||
TMIO_STAT1_DATATIMEOUT | TMIO_STAT1_STOPBIT_ERR | TMIO_STAT1_CRCFAIL | TMIO_STAT1_CMD_IDX_ERR)
|
||||
|
||||
#define TMIO_MASK_READOP (TMIO_STAT1_RXRDY | TMIO_STAT1_DATAEND)
|
||||
#define TMIO_MASK_WRITEOP (TMIO_STAT1_TXRQ | TMIO_STAT1_DATAEND)
|
||||
|
||||
typedef struct mmcdevice {
|
||||
u8 *rData;
|
||||
const u8 *tData;
|
||||
u32 size;
|
||||
u32 error;
|
||||
u16 stat0;
|
||||
u16 stat1;
|
||||
u32 ret[4];
|
||||
u32 initarg;
|
||||
u32 isSDHC;
|
||||
u32 clk;
|
||||
u32 SDOPT;
|
||||
u32 devicenumber;
|
||||
u32 total_size; //size in sectors of the device
|
||||
u32 res;
|
||||
} mmcdevice;
|
||||
|
||||
u32 sdmmc_sdcard_init();
|
||||
int sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, u8 *out);
|
||||
int sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, const u8 *in);
|
||||
int sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, u8 *out);
|
||||
int sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, const u8 *in);
|
||||
void sdmmc_get_cid(bool isNand, u32 *info);
|
||||
mmcdevice *getMMCDevice(int drive);
|
||||
561
arm9/source/firm.c
Executable file
561
arm9/source/firm.c
Executable file
@@ -0,0 +1,561 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "firm.h"
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
#include "fs.h"
|
||||
#include "exceptions.h"
|
||||
#include "patches.h"
|
||||
#include "memory.h"
|
||||
#include "cache.h"
|
||||
#include "emunand.h"
|
||||
#include "crypto.h"
|
||||
#include "screen.h"
|
||||
#include "fmt.h"
|
||||
#include "chainloader.h"
|
||||
|
||||
static Firm *firm = (Firm *)0x20001000;
|
||||
|
||||
static __attribute__((noinline)) bool overlaps(u32 as, u32 ae, u32 bs, u32 be)
|
||||
{
|
||||
if(as <= bs && bs <= ae)
|
||||
return true;
|
||||
if(bs <= as && as <= be)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) bool inRange(u32 as, u32 ae, u32 bs, u32 be)
|
||||
{
|
||||
if(as >= bs && ae <= be)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool checkFirm(u32 firmSize)
|
||||
{
|
||||
if(memcmp(firm->magic, "FIRM", 4) != 0 || firm->arm9Entry == NULL) //Allow for the Arm11 entrypoint to be zero in which case nothing is done on the Arm11 side
|
||||
return false;
|
||||
|
||||
bool arm9EpFound = false,
|
||||
arm11EpFound = false;
|
||||
|
||||
u32 size = 0x200;
|
||||
for(u32 i = 0; i < 4; i++)
|
||||
size += firm->section[i].size;
|
||||
|
||||
if(firmSize < size) return false;
|
||||
|
||||
for(u32 i = 0; i < 4; i++)
|
||||
{
|
||||
FirmSection *section = &firm->section[i];
|
||||
|
||||
//Allow empty sections
|
||||
if(section->size == 0)
|
||||
continue;
|
||||
|
||||
if((section->offset < 0x200) ||
|
||||
(section->address + section->size < section->address) || //Overflow check
|
||||
((u32)section->address & 3) || (section->offset & 0x1FF) || (section->size & 0x1FF) || //Alignment check
|
||||
(overlaps((u32)section->address, (u32)section->address + section->size, (u32)firm, (u32)firm + size)) ||
|
||||
((!inRange((u32)section->address, (u32)section->address + section->size, 0x08000000, 0x08000000 + 0x00100000)) &&
|
||||
(!inRange((u32)section->address, (u32)section->address + section->size, 0x18000000, 0x18000000 + 0x00600000)) &&
|
||||
(!inRange((u32)section->address, (u32)section->address + section->size, 0x1FF00000, 0x1FFFFC00)) &&
|
||||
(!inRange((u32)section->address, (u32)section->address + section->size, 0x20000000, 0x20000000 + 0x8000000))))
|
||||
return false;
|
||||
|
||||
__attribute__((aligned(4))) u8 hash[0x20];
|
||||
|
||||
sha(hash, (u8 *)firm + section->offset, section->size, SHA_256_MODE);
|
||||
|
||||
if(memcmp(hash, section->hash, 0x20) != 0)
|
||||
return false;
|
||||
|
||||
if(firm->arm9Entry >= section->address && firm->arm9Entry < (section->address + section->size))
|
||||
arm9EpFound = true;
|
||||
|
||||
if(firm->arm11Entry >= section->address && firm->arm11Entry < (section->address + section->size))
|
||||
arm11EpFound = true;
|
||||
}
|
||||
|
||||
return arm9EpFound && (firm->arm11Entry == NULL || arm11EpFound);
|
||||
}
|
||||
|
||||
static inline u32 loadFirmFromStorage(FirmwareType firmType)
|
||||
{
|
||||
static const char *firmwareFiles[] = {
|
||||
"native.firm",
|
||||
"twl.firm",
|
||||
"agb.firm",
|
||||
"safe.firm",
|
||||
"sysupdater.firm"
|
||||
},
|
||||
*cetkFiles[] = {
|
||||
"cetk",
|
||||
"cetk_twl",
|
||||
"cetk_agb",
|
||||
"cetk_safe",
|
||||
"cetk_sysupdater"
|
||||
};
|
||||
|
||||
u32 firmSize = fileRead(firm, firmwareFiles[(u32)firmType], 0x400000 + sizeof(Cxi) + 0x200);
|
||||
|
||||
if(!firmSize) return 0;
|
||||
|
||||
static const char *extFirmError = "The external FIRM is not valid.";
|
||||
|
||||
if(firmSize <= sizeof(Cxi) + 0x200) error(extFirmError);
|
||||
|
||||
if(memcmp(firm, "FIRM", 4) != 0)
|
||||
{
|
||||
if(firmSize <= sizeof(Cxi) + 0x400) error(extFirmError);
|
||||
|
||||
u8 cetk[0xA50];
|
||||
|
||||
if(fileRead(cetk, cetkFiles[(u32)firmType], sizeof(cetk)) != sizeof(cetk))
|
||||
error("The cetk is missing or corrupted.");
|
||||
|
||||
firmSize = decryptNusFirm((Ticket *)(cetk + 0x140), (Cxi *)firm, firmSize);
|
||||
|
||||
if(!firmSize) error("Unable to decrypt the external FIRM.");
|
||||
}
|
||||
|
||||
if(!checkFirm(firmSize)) error("The external FIRM is invalid or corrupted.");
|
||||
|
||||
return firmSize;
|
||||
}
|
||||
|
||||
u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode)
|
||||
{
|
||||
u32 firmVersion,
|
||||
firmSize;
|
||||
|
||||
bool ctrNandError = isSdMode && !mountFs(false, false);
|
||||
|
||||
if(!ctrNandError)
|
||||
{
|
||||
//Load FIRM from CTRNAND
|
||||
firmVersion = firmRead(firm, (u32)*firmType);
|
||||
|
||||
if(firmVersion == 0xFFFFFFFF) ctrNandError = true;
|
||||
else
|
||||
{
|
||||
firmSize = decryptExeFs((Cxi *)firm);
|
||||
|
||||
if(!firmSize || !checkFirm(firmSize)) ctrNandError = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool loadedFromStorage = false;
|
||||
|
||||
if(loadFromStorage || ctrNandError)
|
||||
{
|
||||
u32 result = loadFirmFromStorage(*firmType);
|
||||
|
||||
if(result != 0)
|
||||
{
|
||||
loadedFromStorage = true;
|
||||
firmSize = result;
|
||||
}
|
||||
else if(ctrNandError) error("Unable to mount CTRNAND or load the CTRNAND FIRM.\nPlease use an external one.");
|
||||
}
|
||||
|
||||
//Check that the FIRM is right for the console from the Arm9 section address
|
||||
if((firm->section[3].offset != 0 ? firm->section[3].address : firm->section[2].address) != (ISN3DS ? (u8 *)0x8006000 : (u8 *)0x8006800))
|
||||
error("The %s FIRM is not for this console.", loadedFromStorage ? "external" : "CTRNAND");
|
||||
|
||||
if(!ISN3DS && *firmType == NATIVE_FIRM && firm->section[0].address == (u8 *)0x1FF80000)
|
||||
{
|
||||
//We can't boot < 3.x EmuNANDs
|
||||
if(nandType != FIRMWARE_SYSNAND) error("An old unsupported EmuNAND has been detected.\nLuma3DS is unable to boot it.");
|
||||
|
||||
if(isSafeMode) error("SAFE_MODE is not supported on 1.x/2.x FIRM.");
|
||||
|
||||
*firmType = NATIVE_FIRM1X2X;
|
||||
}
|
||||
|
||||
if(loadedFromStorage || ISDEVUNIT)
|
||||
{
|
||||
firmVersion = 0xFFFFFFFF;
|
||||
|
||||
if(!ISN3DS && *firmType == NATIVE_FIRM)
|
||||
{
|
||||
__attribute__((aligned(4))) static const u8 hashes[3][0x20] = {
|
||||
{0x39, 0x75, 0xB5, 0x28, 0x24, 0x5E, 0x8B, 0x56, 0xBC, 0x83, 0x79, 0x41, 0x09, 0x2C, 0x42, 0xE6,
|
||||
0x26, 0xB6, 0x80, 0x59, 0xA5, 0x56, 0xF9, 0xF9, 0x6E, 0xF3, 0x63, 0x05, 0x58, 0xDF, 0x35, 0xEF},
|
||||
{0x81, 0x9E, 0x71, 0x58, 0xE5, 0x44, 0x73, 0xF7, 0x48, 0x78, 0x7C, 0xEF, 0x5E, 0x30, 0xE2, 0x28,
|
||||
0x78, 0x0B, 0x21, 0x23, 0x94, 0x63, 0xE8, 0x4E, 0x06, 0xBB, 0xD6, 0x8D, 0xA0, 0x99, 0xAE, 0x98},
|
||||
{0x1D, 0xD5, 0xB0, 0xC2, 0xD9, 0x4A, 0x4A, 0xF3, 0x23, 0xDD, 0x2F, 0x65, 0x21, 0x95, 0x9B, 0x7E,
|
||||
0xF2, 0x71, 0x7E, 0xB6, 0x7A, 0x3A, 0x74, 0x78, 0x0D, 0xE3, 0xB5, 0x0C, 0x2B, 0x7F, 0x85, 0x37}
|
||||
};
|
||||
|
||||
u32 i;
|
||||
for(i = 0; i < 3; i++) if(memcmp(firm->section[1].hash, hashes[i], 0x20) == 0) break;
|
||||
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
firmVersion = 0x18;
|
||||
break;
|
||||
case 1:
|
||||
firmVersion = 0x1D;
|
||||
break;
|
||||
case 2:
|
||||
firmVersion = 0x1F;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return firmVersion;
|
||||
}
|
||||
|
||||
void loadHomebrewFirm(u32 pressed)
|
||||
{
|
||||
char path[10 + 255];
|
||||
bool found = !pressed ? payloadMenu(path) : findPayload(path, pressed);
|
||||
|
||||
if(!found) return;
|
||||
|
||||
u32 maxPayloadSize = (u32)((u8 *)0x27FFE000 - (u8 *)firm),
|
||||
payloadSize = fileRead(firm, path, maxPayloadSize);
|
||||
|
||||
if(payloadSize <= 0x200 || !checkFirm(payloadSize)) error("The payload is invalid or corrupted.");
|
||||
|
||||
char absPath[24 + 255];
|
||||
|
||||
if(isSdMode) sprintf(absPath, "sdmc:/luma/%s", path);
|
||||
else sprintf(absPath, "nand:/rw/luma/%s", path);
|
||||
|
||||
char *argv[2] = {absPath, (char *)fbs};
|
||||
|
||||
initScreens();
|
||||
|
||||
launchFirm((firm->reserved2[0] & 1) ? 2 : 1, argv);
|
||||
}
|
||||
|
||||
static inline void mergeSection0(FirmwareType firmType, u32 firmVersion, bool loadFromStorage)
|
||||
{
|
||||
u32 srcModuleSize,
|
||||
nbModules = 0;
|
||||
|
||||
struct
|
||||
{
|
||||
char name[8];
|
||||
u8 *src;
|
||||
u32 size;
|
||||
} moduleList[6];
|
||||
|
||||
//1) Parse info concerning Nintendo's modules
|
||||
for(u8 *src = (u8 *)firm + firm->section[0].offset, *srcEnd = src + firm->section[0].size; src < srcEnd; src += srcModuleSize, nbModules++)
|
||||
{
|
||||
memcpy(moduleList[nbModules].name, ((Cxi *)src)->exHeader.systemControlInfo.appTitle, 8);
|
||||
moduleList[nbModules].src = src;
|
||||
srcModuleSize = moduleList[nbModules].size = ((Cxi *)src)->ncch.contentSize * 0x200;
|
||||
}
|
||||
|
||||
// SAFE_FIRM only for N3DS and only if ENABLESAFEFIRMROSALINA is on
|
||||
if((firmType == NATIVE_FIRM || firmType == SAFE_FIRM) && (ISN3DS || firmVersion >= 0x1D))
|
||||
{
|
||||
//2) Merge that info with our own modules'
|
||||
for(u8 *src = (u8 *)0x18180000; memcmp(((Cxi *)src)->ncch.magic, "NCCH", 4) == 0; src += srcModuleSize)
|
||||
{
|
||||
const char *name = ((Cxi *)src)->exHeader.systemControlInfo.appTitle;
|
||||
|
||||
u32 i;
|
||||
|
||||
for(i = 0; i < 5 && memcmp(name, moduleList[i].name, 8) != 0; i++);
|
||||
|
||||
if(i == 5)
|
||||
{
|
||||
nbModules++;
|
||||
memcpy(moduleList[i].name, ((Cxi *)src)->exHeader.systemControlInfo.appTitle, 8);
|
||||
}
|
||||
|
||||
moduleList[i].src = src;
|
||||
srcModuleSize = moduleList[i].size = ((Cxi *)src)->ncch.contentSize * 0x200;
|
||||
}
|
||||
}
|
||||
|
||||
//3) Read or copy the modules
|
||||
u8 *dst = firm->section[0].address;
|
||||
const char *extModuleSizeError = "The external FIRM modules are too large.";
|
||||
// SAFE_FIRM only for N3DS and only if ENABLESAFEFIRMROSALINA is on
|
||||
u32 maxModuleSize = (firmType == NATIVE_FIRM || firmType == SAFE_FIRM) ? 0x80000 : 0x600000;
|
||||
for(u32 i = 0, dstModuleSize; i < nbModules; i++, dst += dstModuleSize, maxModuleSize -= dstModuleSize)
|
||||
{
|
||||
if(loadFromStorage)
|
||||
{
|
||||
char fileName[24];
|
||||
|
||||
//Read modules from files if they exist
|
||||
sprintf(fileName, "sysmodules/%.8s.cxi", moduleList[i].name);
|
||||
|
||||
dstModuleSize = getFileSize(fileName);
|
||||
|
||||
if(dstModuleSize != 0)
|
||||
{
|
||||
if(dstModuleSize > maxModuleSize) error(extModuleSizeError);
|
||||
|
||||
if(dstModuleSize <= sizeof(Cxi) + 0x200 ||
|
||||
fileRead(dst, fileName, dstModuleSize) != dstModuleSize ||
|
||||
memcmp(((Cxi *)dst)->ncch.magic, "NCCH", 4) != 0 ||
|
||||
memcmp(moduleList[i].name, ((Cxi *)dst)->exHeader.systemControlInfo.appTitle, sizeof(((Cxi *)dst)->exHeader.systemControlInfo.appTitle)) != 0)
|
||||
error("An external FIRM module is invalid or corrupted.");
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
dstModuleSize = moduleList[i].size;
|
||||
|
||||
if(dstModuleSize > maxModuleSize) error(extModuleSizeError);
|
||||
|
||||
memcpy(dst, moduleList[i].src, dstModuleSize);
|
||||
}
|
||||
|
||||
//4) Patch NATIVE_FIRM/SAFE_FIRM (N3DS) if necessary
|
||||
if(nbModules == 6)
|
||||
{
|
||||
if(patchK11ModuleLoading(firm->section[0].size, dst - firm->section[0].address, (u8 *)firm + firm->section[1].offset, firm->section[1].size) != 0)
|
||||
error("Failed to inject custom sysmodule");
|
||||
}
|
||||
}
|
||||
|
||||
u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool needToInitSd, bool doUnitinfoPatch)
|
||||
{
|
||||
u8 *arm9Section = (u8 *)firm + firm->section[2].offset,
|
||||
*arm11Section1 = (u8 *)firm + firm->section[1].offset;
|
||||
|
||||
if(ISN3DS)
|
||||
{
|
||||
//Decrypt Arm9Bin and patch Arm9 entrypoint to skip kernel9loader
|
||||
kernel9Loader((Arm9Bin *)arm9Section);
|
||||
firm->arm9Entry = (u8 *)0x801B01C;
|
||||
}
|
||||
|
||||
//Find the Process9 .code location, size and memory address
|
||||
u32 process9Size,
|
||||
process9MemAddr;
|
||||
u8 *process9Offset = getProcess9Info(arm9Section, firm->section[2].size, &process9Size, &process9MemAddr);
|
||||
|
||||
//Find the Kernel11 SVC table and handler, exceptions page and free space locations
|
||||
u32 baseK11VA;
|
||||
u8 *freeK11Space;
|
||||
u32 *arm11SvcHandler,
|
||||
*arm11ExceptionsPage,
|
||||
*arm11SvcTable = getKernel11Info(arm11Section1, firm->section[1].size, &baseK11VA, &freeK11Space, &arm11SvcHandler, &arm11ExceptionsPage);
|
||||
|
||||
u32 kernel9Size = (u32)(process9Offset - arm9Section) - sizeof(Cxi) - 0x200,
|
||||
ret = 0;
|
||||
|
||||
//Skip on FIRMs < 4.0
|
||||
if(ISN3DS || firmVersion >= 0x1D)
|
||||
{
|
||||
ret += installK11Extension(arm11Section1, firm->section[1].size, needToInitSd, baseK11VA, arm11ExceptionsPage, &freeK11Space);
|
||||
ret += patchKernel11(arm11Section1, firm->section[1].size, baseK11VA, arm11SvcTable, arm11ExceptionsPage);
|
||||
}
|
||||
|
||||
//Apply signature patches
|
||||
ret += patchSignatureChecks(process9Offset, process9Size);
|
||||
|
||||
//Apply EmuNAND patches
|
||||
if(nandType != FIRMWARE_SYSNAND) ret += patchEmuNand(arm9Section, kernel9Size, process9Offset, process9Size, firm->section[2].address, firmVersion);
|
||||
|
||||
//Apply FIRM0/1 writes patches on SysNAND to protect A9LH
|
||||
else if(isFirmProtEnabled) ret += patchFirmWrites(process9Offset, process9Size);
|
||||
|
||||
//Apply firmlaunch patches
|
||||
ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr);
|
||||
|
||||
//Apply dev unit check patches related to NCCH encryption
|
||||
if(!ISDEVUNIT)
|
||||
{
|
||||
ret += patchZeroKeyNcchEncryptionCheck(process9Offset, process9Size);
|
||||
ret += patchNandNcchEncryptionCheck(process9Offset, process9Size);
|
||||
}
|
||||
|
||||
//Apply anti-anti-DG patches on 11.0+
|
||||
if(firmVersion >= (ISN3DS ? 0x21 : 0x52)) ret += patchTitleInstallMinVersionChecks(process9Offset, process9Size, firmVersion);
|
||||
|
||||
//Patch P9 AM ticket wrapper on 11.8+ to use 0 Key and IV, only with UNITINFO patch on to prevent NIM from actually sending any
|
||||
if(doUnitinfoPatch && firmVersion >= (ISN3DS ? 0x35 : 0x64)) ret += patchP9AMTicketWrapperZeroKeyIV(process9Offset, process9Size, firmVersion);
|
||||
|
||||
//Apply UNITINFO patches
|
||||
if(doUnitinfoPatch)
|
||||
{
|
||||
ret += patchUnitInfoValueSet(arm9Section, kernel9Size);
|
||||
if(!ISDEVUNIT) ret += patchCheckForDevCommonKey(process9Offset, process9Size);
|
||||
}
|
||||
|
||||
//Arm9 exception handlers
|
||||
ret += patchArm9ExceptionHandlersInstall(arm9Section, kernel9Size);
|
||||
ret += patchSvcBreak9(arm9Section, kernel9Size, (u32)firm->section[2].address);
|
||||
ret += patchKernel9Panic(arm9Section, kernel9Size);
|
||||
|
||||
ret += patchP9AccessChecks(process9Offset, process9Size);
|
||||
|
||||
mergeSection0(NATIVE_FIRM, firmVersion, loadFromStorage);
|
||||
firm->section[0].size = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 patchTwlFirm(u32 firmVersion, bool loadFromStorage, bool doUnitinfoPatch)
|
||||
{
|
||||
u8 *arm9Section = (u8 *)firm + firm->section[3].offset;
|
||||
|
||||
//On N3DS, decrypt Arm9Bin and patch Arm9 entrypoint to skip kernel9loader
|
||||
if(ISN3DS)
|
||||
{
|
||||
kernel9Loader((Arm9Bin *)arm9Section);
|
||||
firm->arm9Entry = (u8 *)0x801301C;
|
||||
}
|
||||
|
||||
//Find the Process9 .code location, size and memory address
|
||||
u32 process9Size,
|
||||
process9MemAddr;
|
||||
u8 *process9Offset = getProcess9Info(arm9Section, firm->section[3].size, &process9Size, &process9MemAddr);
|
||||
|
||||
u32 kernel9Size = (u32)(process9Offset - arm9Section) - sizeof(Cxi) - 0x200,
|
||||
ret = 0;
|
||||
|
||||
ret += patchLgySignatureChecks(process9Offset, process9Size);
|
||||
ret += patchTwlInvalidSignatureChecks(process9Offset, process9Size);
|
||||
ret += patchTwlNintendoLogoChecks(process9Offset, process9Size);
|
||||
ret += patchTwlWhitelistChecks(process9Offset, process9Size);
|
||||
if(ISN3DS || firmVersion > 0x11) ret += patchTwlFlashcartChecks(process9Offset, process9Size, firmVersion);
|
||||
else if(!ISN3DS && firmVersion == 0x11) ret += patchOldTwlFlashcartChecks(process9Offset, process9Size);
|
||||
ret += patchTwlShaHashChecks(process9Offset, process9Size);
|
||||
|
||||
//Apply UNITINFO patch
|
||||
if(doUnitinfoPatch) ret += patchUnitInfoValueSet(arm9Section, kernel9Size);
|
||||
|
||||
if(loadFromStorage)
|
||||
{
|
||||
mergeSection0(TWL_FIRM, 0, true);
|
||||
firm->section[0].size = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 patchAgbFirm(bool loadFromStorage, bool doUnitinfoPatch)
|
||||
{
|
||||
u8 *arm9Section = (u8 *)firm + firm->section[3].offset;
|
||||
|
||||
//On N3DS, decrypt Arm9Bin and patch Arm9 entrypoint to skip kernel9loader
|
||||
if(ISN3DS)
|
||||
{
|
||||
kernel9Loader((Arm9Bin *)arm9Section);
|
||||
firm->arm9Entry = (u8 *)0x801301C;
|
||||
}
|
||||
|
||||
//Find the Process9 .code location, size and memory address
|
||||
u32 process9Size,
|
||||
process9MemAddr;
|
||||
u8 *process9Offset = getProcess9Info(arm9Section, firm->section[3].size, &process9Size, &process9MemAddr);
|
||||
|
||||
u32 kernel9Size = (u32)(process9Offset - arm9Section) - sizeof(Cxi) - 0x200,
|
||||
ret = 0;
|
||||
|
||||
ret += patchLgySignatureChecks(process9Offset, process9Size);
|
||||
if(CONFIG(SHOWGBABOOT)) ret += patchAgbBootSplash(process9Offset, process9Size);
|
||||
|
||||
//Apply UNITINFO patch
|
||||
if(doUnitinfoPatch) ret += patchUnitInfoValueSet(arm9Section, kernel9Size);
|
||||
|
||||
if(loadFromStorage)
|
||||
{
|
||||
mergeSection0(AGB_FIRM, 0, true);
|
||||
firm->section[0].size = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 patch1x2xNativeAndSafeFirm(void)
|
||||
{
|
||||
u8 *arm9Section = (u8 *)firm + firm->section[2].offset;
|
||||
|
||||
if(ISN3DS)
|
||||
{
|
||||
//Decrypt Arm9Bin and patch Arm9 entrypoint to skip kernel9loader
|
||||
kernel9Loader((Arm9Bin *)arm9Section);
|
||||
firm->arm9Entry = (u8 *)0x801B01C;
|
||||
}
|
||||
|
||||
//Find the Process9 .code location, size and memory address
|
||||
u32 process9Size,
|
||||
process9MemAddr;
|
||||
u8 *process9Offset = getProcess9Info(arm9Section, firm->section[2].size, &process9Size, &process9MemAddr);
|
||||
|
||||
u32 kernel9Size = (u32)(process9Offset - arm9Section) - sizeof(Cxi) - 0x200,
|
||||
ret = 0;
|
||||
|
||||
ret += ISN3DS ? patchFirmWrites(process9Offset, process9Size) : patchOldFirmWrites(process9Offset, process9Size);
|
||||
|
||||
ret += ISN3DS ? patchSignatureChecks(process9Offset, process9Size) : patchOldSignatureChecks(process9Offset, process9Size);
|
||||
|
||||
//Arm9 exception handlers
|
||||
ret += patchArm9ExceptionHandlersInstall(arm9Section, kernel9Size);
|
||||
ret += patchSvcBreak9(arm9Section, kernel9Size, (u32)firm->section[2].address);
|
||||
|
||||
if(ISN3DS && CONFIG(ENABLESAFEFIRMROSALINA))
|
||||
{
|
||||
u8 *arm11Section1 = (u8 *)firm + firm->section[1].offset;
|
||||
//Find the Kernel11 SVC table and handler, exceptions page and free space locations
|
||||
u32 baseK11VA;
|
||||
u8 *freeK11Space;
|
||||
u32 *arm11SvcHandler,
|
||||
*arm11ExceptionsPage,
|
||||
*arm11SvcTable = getKernel11Info(arm11Section1, firm->section[1].size, &baseK11VA, &freeK11Space, &arm11SvcHandler, &arm11ExceptionsPage);
|
||||
|
||||
ret += installK11Extension(arm11Section1, firm->section[1].size, false, baseK11VA, arm11ExceptionsPage, &freeK11Space);
|
||||
ret += patchKernel11(arm11Section1, firm->section[1].size, baseK11VA, arm11SvcTable, arm11ExceptionsPage);
|
||||
|
||||
// Add some other patches to the mix, as we can now launch homebrew on SAFE_FIRM:
|
||||
|
||||
//Apply firmlaunch patches
|
||||
//Or don't, this makes usm not work
|
||||
//ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr);
|
||||
|
||||
ret += patchKernel9Panic(arm9Section, kernel9Size);
|
||||
ret += patchP9AccessChecks(process9Offset, process9Size);
|
||||
|
||||
mergeSection0(NATIVE_FIRM, 0x45, false); // may change in the future
|
||||
firm->section[0].size = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void launchFirm(int argc, char **argv)
|
||||
{
|
||||
prepareArm11ForFirmlaunch();
|
||||
chainload(argc, argv, firm);
|
||||
}
|
||||
38
arm9/source/firm.h
Normal file
38
arm9/source/firm.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "3dsheaders.h"
|
||||
|
||||
u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode);
|
||||
void loadHomebrewFirm(u32 pressed);
|
||||
u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool needToInitSd, bool doUnitinfoPatch);
|
||||
u32 patchTwlFirm(u32 firmVersion, bool loadFromStorage, bool doUnitinfoPatch);
|
||||
u32 patchAgbFirm(bool loadFromStorage, bool doUnitinfoPatch);
|
||||
u32 patch1x2xNativeAndSafeFirm(void);
|
||||
void launchFirm(int argc, char **argv);
|
||||
319
arm9/source/fmt.c
Normal file
319
arm9/source/fmt.c
Normal file
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/* File : barebones/ee_printf.c
|
||||
This file contains an implementation of ee_printf that only requires a method to output a char to a UART without pulling in library code.
|
||||
|
||||
This code is based on a file that contains the following:
|
||||
Copyright (C) 2002 Michael Ringgaard. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the project nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
//TuxSH's changes: add support for 64-bit numbers, remove floating-point code
|
||||
|
||||
#include "memory.h"
|
||||
#include "fmt.h"
|
||||
|
||||
#define ZEROPAD (1<<0) //Pad with zero
|
||||
#define SIGN (1<<1) //Unsigned/signed long
|
||||
#define PLUS (1<<2) //Show plus
|
||||
#define SPACE (1<<3) //Spacer
|
||||
#define LEFT (1<<4) //Left justified
|
||||
#define HEX_PREP (1<<5) //0x
|
||||
#define UPPERCASE (1<<6) //'ABCDEF'
|
||||
|
||||
#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
|
||||
|
||||
static s32 skipAtoi(const char **s)
|
||||
{
|
||||
s32 i = 0;
|
||||
|
||||
while(IS_DIGIT(**s)) i = i * 10 + *((*s)++) - '0';
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static char *processNumber(char *str, s64 num, bool isHex, s32 size, s32 precision, u32 type)
|
||||
{
|
||||
char sign = 0;
|
||||
|
||||
if(type & SIGN)
|
||||
{
|
||||
if(num < 0)
|
||||
{
|
||||
sign = '-';
|
||||
num = -num;
|
||||
size--;
|
||||
}
|
||||
else if(type & PLUS)
|
||||
{
|
||||
sign = '+';
|
||||
size--;
|
||||
}
|
||||
else if(type & SPACE)
|
||||
{
|
||||
sign = ' ';
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *lowerDigits = "0123456789abcdef",
|
||||
*upperDigits = "0123456789ABCDEF";
|
||||
|
||||
s32 i = 0;
|
||||
char tmp[20];
|
||||
const char *dig = (type & UPPERCASE) ? upperDigits : lowerDigits;
|
||||
|
||||
if(num == 0)
|
||||
{
|
||||
if(precision != 0) tmp[i++] = '0';
|
||||
type &= ~HEX_PREP;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(num != 0)
|
||||
{
|
||||
u64 base = isHex ? 16ULL : 10ULL;
|
||||
tmp[i++] = dig[(u64)num % base];
|
||||
num = (s64)((u64)num / base);
|
||||
}
|
||||
}
|
||||
|
||||
if(type & LEFT || precision != -1) type &= ~ZEROPAD;
|
||||
if(type & HEX_PREP && isHex) size -= 2;
|
||||
if(i > precision) precision = i;
|
||||
size -= precision;
|
||||
if(!(type & (ZEROPAD | LEFT))) while(size-- > 0) *str++ = ' ';
|
||||
if(sign) *str++ = sign;
|
||||
|
||||
if(type & HEX_PREP && isHex)
|
||||
{
|
||||
*str++ = '0';
|
||||
*str++ = 'x';
|
||||
}
|
||||
|
||||
if(type & ZEROPAD) while(size-- > 0) *str++ = '0';
|
||||
while(i < precision--) *str++ = '0';
|
||||
while(i-- > 0) *str++ = tmp[i];
|
||||
while(size-- > 0) *str++ = ' ';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
int vsprintf(char *buf, const char *fmt, va_list args)
|
||||
{
|
||||
char *str;
|
||||
|
||||
for(str = buf; *fmt; fmt++)
|
||||
{
|
||||
if(*fmt != '%')
|
||||
{
|
||||
*str++ = *fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Process flags
|
||||
u32 flags = 0; //Flags to number()
|
||||
bool loop = true;
|
||||
|
||||
while(loop)
|
||||
{
|
||||
switch(*++fmt)
|
||||
{
|
||||
case '-': flags |= LEFT; break;
|
||||
case '+': flags |= PLUS; break;
|
||||
case ' ': flags |= SPACE; break;
|
||||
case '#': flags |= HEX_PREP; break;
|
||||
case '0': flags |= ZEROPAD; break;
|
||||
default: loop = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
//Get field width
|
||||
s32 fieldWidth = -1; //Width of output field
|
||||
if(IS_DIGIT(*fmt)) fieldWidth = skipAtoi(&fmt);
|
||||
else if(*fmt == '*')
|
||||
{
|
||||
fmt++;
|
||||
|
||||
fieldWidth = va_arg(args, s32);
|
||||
|
||||
if(fieldWidth < 0)
|
||||
{
|
||||
fieldWidth = -fieldWidth;
|
||||
flags |= LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
//Get the precision
|
||||
s32 precision = -1; //Min. # of digits for integers; max number of chars for from string
|
||||
if(*fmt == '.')
|
||||
{
|
||||
fmt++;
|
||||
|
||||
if(IS_DIGIT(*fmt)) precision = skipAtoi(&fmt);
|
||||
else if(*fmt == '*')
|
||||
{
|
||||
fmt++;
|
||||
precision = va_arg(args, s32);
|
||||
}
|
||||
|
||||
if(precision < 0) precision = 0;
|
||||
}
|
||||
|
||||
//Get the conversion qualifier
|
||||
u32 integerType = 0;
|
||||
if(*fmt == 'l')
|
||||
{
|
||||
if(*++fmt == 'l')
|
||||
{
|
||||
fmt++;
|
||||
integerType = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else if(*fmt == 'h')
|
||||
{
|
||||
if(*++fmt == 'h')
|
||||
{
|
||||
fmt++;
|
||||
integerType = 3;
|
||||
}
|
||||
else integerType = 2;
|
||||
}
|
||||
|
||||
bool isHex;
|
||||
|
||||
switch(*fmt)
|
||||
{
|
||||
case 'c':
|
||||
if(!(flags & LEFT)) while(--fieldWidth > 0) *str++ = ' ';
|
||||
*str++ = (u8)va_arg(args, s32);
|
||||
while(--fieldWidth > 0) *str++ = ' ';
|
||||
continue;
|
||||
|
||||
case 's':
|
||||
{
|
||||
char *s = va_arg(args, char *);
|
||||
if(!s) s = "<NULL>";
|
||||
u32 len = (precision != -1) ? strnlen(s, precision) : strlen(s);
|
||||
if(!(flags & LEFT)) while((s32)len < fieldWidth--) *str++ = ' ';
|
||||
for(u32 i = 0; i < len; i++) *str++ = *s++;
|
||||
while((s32)len < fieldWidth--) *str++ = ' ';
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'p':
|
||||
if(fieldWidth == -1)
|
||||
{
|
||||
fieldWidth = 8;
|
||||
flags |= ZEROPAD;
|
||||
}
|
||||
str = processNumber(str, va_arg(args, u32), true, fieldWidth, precision, flags);
|
||||
continue;
|
||||
|
||||
//Integer number formats - set up the flags and "break"
|
||||
case 'X':
|
||||
flags |= UPPERCASE;
|
||||
//Falls through
|
||||
case 'x':
|
||||
isHex = true;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
flags |= SIGN;
|
||||
//Falls through
|
||||
case 'u':
|
||||
isHex = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(*fmt != '%') *str++ = '%';
|
||||
if(*fmt) *str++ = *fmt;
|
||||
else fmt--;
|
||||
continue;
|
||||
}
|
||||
|
||||
s64 num;
|
||||
|
||||
if(flags & SIGN)
|
||||
{
|
||||
if(integerType == 1) num = va_arg(args, s64);
|
||||
else num = va_arg(args, s32);
|
||||
|
||||
if(integerType == 2) num = (s16)num;
|
||||
else if(integerType == 3) num = (s8)num;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(integerType == 1) num = va_arg(args, u64);
|
||||
else num = va_arg(args, u32);
|
||||
|
||||
if(integerType == 2) num = (u16)num;
|
||||
else if(integerType == 3) num = (u8)num;
|
||||
}
|
||||
|
||||
str = processNumber(str, num, isHex, fieldWidth, precision, flags);
|
||||
}
|
||||
|
||||
*str = 0;
|
||||
return (int)(str - buf);
|
||||
}
|
||||
|
||||
int sprintf(char *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int res = vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
32
arm9/source/fmt.h
Normal file
32
arm9/source/fmt.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "memory.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
int vsprintf(char *buf, const char *fmt, va_list args);
|
||||
int sprintf(char *buf, const char *fmt, ...);
|
||||
309
arm9/source/fs.c
Normal file
309
arm9/source/fs.c
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "fs.h"
|
||||
#include "memory.h"
|
||||
#include "fmt.h"
|
||||
#include "crypto.h"
|
||||
#include "cache.h"
|
||||
#include "screen.h"
|
||||
#include "draw.h"
|
||||
#include "utils.h"
|
||||
#include "fatfs/ff.h"
|
||||
#include "buttons.h"
|
||||
#include "firm.h"
|
||||
#include "crypto.h"
|
||||
#include "strings.h"
|
||||
|
||||
static FATFS sdFs,
|
||||
nandFs;
|
||||
|
||||
static bool switchToMainDir(bool isSd)
|
||||
{
|
||||
const char *mainDir = isSd ? "/luma" : "/rw/luma";
|
||||
|
||||
switch(f_chdir(mainDir))
|
||||
{
|
||||
case FR_OK:
|
||||
return true;
|
||||
case FR_NO_PATH:
|
||||
return f_mkdir(mainDir) == FR_OK && switchToMainDir(isSd);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool mountFs(bool isSd, bool switchToCtrNand)
|
||||
{
|
||||
return isSd ? f_mount(&sdFs, "0:", 1) == FR_OK && switchToMainDir(true) :
|
||||
f_mount(&nandFs, "1:", 1) == FR_OK && (!switchToCtrNand || (f_chdrive("1:") == FR_OK && switchToMainDir(false)));
|
||||
}
|
||||
|
||||
u32 fileRead(void *dest, const char *path, u32 maxSize)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT result = FR_OK;
|
||||
u32 ret = 0;
|
||||
|
||||
if(f_open(&file, path, FA_READ) != FR_OK) return ret;
|
||||
|
||||
u32 size = f_size(&file);
|
||||
if(dest == NULL) ret = size;
|
||||
else if(size <= maxSize)
|
||||
result = f_read(&file, dest, size, (unsigned int *)&ret);
|
||||
result |= f_close(&file);
|
||||
|
||||
return result == FR_OK ? ret : 0;
|
||||
}
|
||||
|
||||
u32 getFileSize(const char *path)
|
||||
{
|
||||
return fileRead(NULL, path, 0);
|
||||
}
|
||||
|
||||
bool fileWrite(const void *buffer, const char *path, u32 size)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT result = FR_OK;
|
||||
|
||||
switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS))
|
||||
{
|
||||
case FR_OK:
|
||||
{
|
||||
unsigned int written;
|
||||
result = f_write(&file, buffer, size, &written);
|
||||
if(result == FR_OK) result = f_truncate(&file);
|
||||
result |= f_close(&file);
|
||||
|
||||
return result == FR_OK && (u32)written == size;
|
||||
}
|
||||
case FR_NO_PATH:
|
||||
for(u32 i = 1; path[i] != 0; i++)
|
||||
if(path[i] == '/')
|
||||
{
|
||||
char folder[i + 1];
|
||||
memcpy(folder, path, i);
|
||||
folder[i] = 0;
|
||||
result = f_mkdir(folder);
|
||||
}
|
||||
|
||||
return result == FR_OK && fileWrite(buffer, path, size);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool fileDelete(const char *path)
|
||||
{
|
||||
return f_unlink(path) == FR_OK;
|
||||
}
|
||||
|
||||
bool findPayload(char *path, u32 pressed)
|
||||
{
|
||||
const char *pattern;
|
||||
|
||||
if(pressed & BUTTON_LEFT) pattern = PATTERN("left");
|
||||
else if(pressed & BUTTON_RIGHT) pattern = PATTERN("right");
|
||||
else if(pressed & BUTTON_UP) pattern = PATTERN("up");
|
||||
else if(pressed & BUTTON_DOWN) pattern = PATTERN("down");
|
||||
else if(pressed & BUTTON_START) pattern = PATTERN("start");
|
||||
else if(pressed & BUTTON_B) pattern = PATTERN("b");
|
||||
else if(pressed & BUTTON_X) pattern = PATTERN("x");
|
||||
else if(pressed & BUTTON_Y) pattern = PATTERN("y");
|
||||
else if(pressed & BUTTON_R1) pattern = PATTERN("r");
|
||||
else if(pressed & BUTTON_A) pattern = PATTERN("a");
|
||||
else pattern = PATTERN("select");
|
||||
|
||||
DIR dir;
|
||||
FILINFO info;
|
||||
FRESULT result;
|
||||
|
||||
result = f_findfirst(&dir, &info, "payloads", pattern);
|
||||
|
||||
if(result != FR_OK) return false;
|
||||
|
||||
f_closedir(&dir);
|
||||
|
||||
if(!info.fname[0]) return false;
|
||||
|
||||
sprintf(path, "payloads/%s", info.fname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool payloadMenu(char *path)
|
||||
{
|
||||
DIR dir;
|
||||
|
||||
if(f_opendir(&dir, "payloads") != FR_OK) return false;
|
||||
|
||||
FILINFO info;
|
||||
u32 payloadNum = 0;
|
||||
char payloadList[20][49];
|
||||
|
||||
while(f_readdir(&dir, &info) == FR_OK && info.fname[0] != 0 && payloadNum < 20)
|
||||
{
|
||||
if(info.fname[0] == '.') continue;
|
||||
|
||||
u32 nameLength = strlen(info.fname);
|
||||
|
||||
if(nameLength < 6 || nameLength > 52) continue;
|
||||
|
||||
nameLength -= 5;
|
||||
|
||||
if(memcmp(info.fname + nameLength, ".firm", 5) != 0) continue;
|
||||
|
||||
memcpy(payloadList[payloadNum], info.fname, nameLength);
|
||||
payloadList[payloadNum][nameLength] = 0;
|
||||
payloadNum++;
|
||||
}
|
||||
|
||||
if(f_closedir(&dir) != FR_OK || !payloadNum) return false;
|
||||
|
||||
u32 pressed = 0,
|
||||
selectedPayload = 0;
|
||||
|
||||
if(payloadNum != 1)
|
||||
{
|
||||
initScreens();
|
||||
|
||||
drawString(true, 10, 10, COLOR_TITLE, "Luma3DS chainloader");
|
||||
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press A to select, START to quit");
|
||||
|
||||
for(u32 i = 0, posY = 10 + 3 * SPACING_Y, color = COLOR_RED; i < payloadNum; i++, posY += SPACING_Y)
|
||||
{
|
||||
drawString(true, 10, posY, color, payloadList[i]);
|
||||
if(color == COLOR_RED) color = COLOR_WHITE;
|
||||
}
|
||||
|
||||
while(pressed != BUTTON_A && pressed != BUTTON_START)
|
||||
{
|
||||
do
|
||||
{
|
||||
pressed = waitInput(true) & MENU_BUTTONS;
|
||||
}
|
||||
while(!pressed);
|
||||
|
||||
u32 oldSelectedPayload = selectedPayload;
|
||||
|
||||
switch(pressed)
|
||||
{
|
||||
case BUTTON_UP:
|
||||
selectedPayload = !selectedPayload ? payloadNum - 1 : selectedPayload - 1;
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
selectedPayload = selectedPayload == payloadNum - 1 ? 0 : selectedPayload + 1;
|
||||
break;
|
||||
case BUTTON_LEFT:
|
||||
selectedPayload = 0;
|
||||
break;
|
||||
case BUTTON_RIGHT:
|
||||
selectedPayload = payloadNum - 1;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
if(oldSelectedPayload == selectedPayload) continue;
|
||||
|
||||
drawString(true, 10, 10 + (3 + oldSelectedPayload) * SPACING_Y, COLOR_WHITE, payloadList[oldSelectedPayload]);
|
||||
drawString(true, 10, 10 + (3 + selectedPayload) * SPACING_Y, COLOR_RED, payloadList[selectedPayload]);
|
||||
}
|
||||
}
|
||||
|
||||
if(pressed != BUTTON_START)
|
||||
{
|
||||
sprintf(path, "payloads/%s.firm", payloadList[selectedPayload]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
while(HID_PAD & MENU_BUTTONS);
|
||||
wait(2000ULL);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 firmRead(void *dest, u32 firmType)
|
||||
{
|
||||
static const char *firmFolders[][2] = {{"00000002", "20000002"},
|
||||
{"00000102", "20000102"},
|
||||
{"00000202", "20000202"},
|
||||
{"00000003", "20000003"},
|
||||
{"00000001", "20000001"}};
|
||||
|
||||
char folderPath[35],
|
||||
path[48];
|
||||
|
||||
sprintf(folderPath, "1:/title/00040138/%s/content", firmFolders[firmType][ISN3DS ? 1 : 0]);
|
||||
|
||||
DIR dir;
|
||||
u32 firmVersion = 0xFFFFFFFF;
|
||||
|
||||
if(f_opendir(&dir, folderPath) != FR_OK) goto exit;
|
||||
|
||||
FILINFO info;
|
||||
|
||||
//Parse the target directory
|
||||
while(f_readdir(&dir, &info) == FR_OK && info.fname[0] != 0)
|
||||
{
|
||||
//Not a cxi
|
||||
if(info.fname[9] != 'a' || strlen(info.fname) != 12) continue;
|
||||
|
||||
u32 tempVersion = hexAtoi(info.altname, 8);
|
||||
|
||||
//Found an older cxi
|
||||
if(tempVersion < firmVersion) firmVersion = tempVersion;
|
||||
}
|
||||
|
||||
if(f_closedir(&dir) != FR_OK || firmVersion == 0xFFFFFFFF) goto exit;
|
||||
|
||||
//Complete the string with the .app name
|
||||
sprintf(path, "%s/%08lx.app", folderPath, firmVersion);
|
||||
|
||||
if(fileRead(dest, path, 0x400000 + sizeof(Cxi) + 0x200) <= sizeof(Cxi) + 0x400) firmVersion = 0xFFFFFFFF;
|
||||
|
||||
exit:
|
||||
return firmVersion;
|
||||
}
|
||||
|
||||
void findDumpFile(const char *folderPath, char *fileName)
|
||||
{
|
||||
DIR dir;
|
||||
FRESULT result;
|
||||
|
||||
for(u32 n = 0; n <= 99999999; n++)
|
||||
{
|
||||
FILINFO info;
|
||||
|
||||
sprintf(fileName, "crash_dump_%08lu.dmp", n);
|
||||
result = f_findfirst(&dir, &info, folderPath, fileName);
|
||||
|
||||
if(result != FR_OK || !info.fname[0]) break;
|
||||
}
|
||||
|
||||
if(result == FR_OK) f_closedir(&dir);
|
||||
}
|
||||
41
arm9/source/fs.h
Normal file
41
arm9/source/fs.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define PATTERN(a) a "_*.firm"
|
||||
|
||||
bool mountFs(bool isSd, bool switchToCtrNand);
|
||||
u32 fileRead(void *dest, const char *path, u32 maxSize);
|
||||
u32 getFileSize(const char *path);
|
||||
bool fileWrite(const void *buffer, const char *path, u32 size);
|
||||
bool fileDelete(const char *path);
|
||||
bool findPayload(char *path, u32 pressed);
|
||||
bool payloadMenu(char *path);
|
||||
u32 firmRead(void *dest, u32 firmType);
|
||||
void findDumpFile(const char *folderPath, char *fileName);
|
||||
225
arm9/source/i2c.c
Normal file
225
arm9/source/i2c.c
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* This file is part of fastboot 3DS
|
||||
* Copyright (C) 2017 derrek, profi200
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "types.h"
|
||||
#include "i2c.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define I2C1_REGS_BASE (0x10161000)
|
||||
|
||||
#define I2C2_REGS_BASE (0x10144000)
|
||||
|
||||
#define I2C3_REGS_BASE (0x10148000)
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vu8 REG_I2C_DATA;
|
||||
vu8 REG_I2C_CNT;
|
||||
vu16 REG_I2C_CNTEX;
|
||||
vu16 REG_I2C_SCL;
|
||||
} I2cRegs;
|
||||
|
||||
static const struct
|
||||
{
|
||||
u8 busId;
|
||||
u8 devAddr;
|
||||
} i2cDevTable[] =
|
||||
{
|
||||
{0, 0x4A},
|
||||
{0, 0x7A},
|
||||
{0, 0x78},
|
||||
{1, 0x4A},
|
||||
{1, 0x78},
|
||||
{1, 0x2C},
|
||||
{1, 0x2E},
|
||||
{1, 0x40},
|
||||
{1, 0x44},
|
||||
{2, 0xA6}, // TODO: Find out if 0xA6 or 0xD6 is correct
|
||||
{2, 0xD0},
|
||||
{2, 0xD2},
|
||||
{2, 0xA4},
|
||||
{2, 0x9A},
|
||||
{2, 0xA0},
|
||||
{1, 0xEE},
|
||||
{0, 0x40},
|
||||
{2, 0x54}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void i2cWaitBusy(I2cRegs *const regs)
|
||||
{
|
||||
while(regs->REG_I2C_CNT & I2C_ENABLE);
|
||||
}
|
||||
|
||||
static I2cRegs* i2cGetBusRegsBase(u8 busId)
|
||||
{
|
||||
I2cRegs *base;
|
||||
switch(busId)
|
||||
{
|
||||
case 0:
|
||||
base = (I2cRegs*)I2C1_REGS_BASE;
|
||||
break;
|
||||
case 1:
|
||||
base = (I2cRegs*)I2C2_REGS_BASE;
|
||||
break;
|
||||
case 2:
|
||||
base = (I2cRegs*)I2C3_REGS_BASE;
|
||||
break;
|
||||
default:
|
||||
base = NULL;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
void I2C_init(void)
|
||||
{
|
||||
I2cRegs *regs = i2cGetBusRegsBase(0); // Bus 1
|
||||
i2cWaitBusy(regs);
|
||||
regs->REG_I2C_CNTEX = 2; // ?
|
||||
regs->REG_I2C_SCL = 1280; // ?
|
||||
|
||||
regs = i2cGetBusRegsBase(1); // Bus 2
|
||||
i2cWaitBusy(regs);
|
||||
regs->REG_I2C_CNTEX = 2; // ?
|
||||
regs->REG_I2C_SCL = 1280; // ?
|
||||
|
||||
regs = i2cGetBusRegsBase(2); // Bus 3
|
||||
i2cWaitBusy(regs);
|
||||
regs->REG_I2C_CNTEX = 2; // ?
|
||||
regs->REG_I2C_SCL = 1280; // ?
|
||||
}
|
||||
|
||||
static bool i2cStartTransfer(I2cDevice devId, u8 regAddr, bool read, I2cRegs *const regs)
|
||||
{
|
||||
const u8 devAddr = i2cDevTable[devId].devAddr;
|
||||
|
||||
|
||||
u32 i = 0;
|
||||
for(; i < 8; i++)
|
||||
{
|
||||
i2cWaitBusy(regs);
|
||||
|
||||
// Select device and start.
|
||||
regs->REG_I2C_DATA = devAddr;
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
|
||||
i2cWaitBusy(regs);
|
||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||
{
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Select register and change direction to write.
|
||||
regs->REG_I2C_DATA = regAddr;
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
|
||||
i2cWaitBusy(regs);
|
||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||
{
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Select device in read mode for read transfer.
|
||||
if(read)
|
||||
{
|
||||
regs->REG_I2C_DATA = devAddr | 1u; // Set bit 0 for read.
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_START;
|
||||
i2cWaitBusy(regs);
|
||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||
{
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(i < 8) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size)
|
||||
{
|
||||
const u8 busId = i2cDevTable[devId].busId;
|
||||
I2cRegs *const regs = i2cGetBusRegsBase(busId);
|
||||
|
||||
|
||||
if(!i2cStartTransfer(devId, regAddr, true, regs)) return false;
|
||||
|
||||
while(--size)
|
||||
{
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_ACK;
|
||||
i2cWaitBusy(regs);
|
||||
*out++ = regs->REG_I2C_DATA;
|
||||
}
|
||||
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_READ | I2C_STOP;
|
||||
i2cWaitBusy(regs);
|
||||
*out = regs->REG_I2C_DATA; // Last byte
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size)
|
||||
{
|
||||
const u8 busId = i2cDevTable[devId].busId;
|
||||
I2cRegs *const regs = i2cGetBusRegsBase(busId);
|
||||
|
||||
|
||||
if(!i2cStartTransfer(devId, regAddr, false, regs)) return false;
|
||||
|
||||
while(--size)
|
||||
{
|
||||
regs->REG_I2C_DATA = *in++;
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE;
|
||||
i2cWaitBusy(regs);
|
||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||
{
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
regs->REG_I2C_DATA = *in;
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_DIRE_WRITE | I2C_STOP;
|
||||
i2cWaitBusy(regs);
|
||||
if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed.
|
||||
{
|
||||
regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
u8 I2C_readReg(I2cDevice devId, u8 regAddr)
|
||||
{
|
||||
u8 data;
|
||||
if(!I2C_readRegBuf(devId, regAddr, &data, 1)) return 0xFF;
|
||||
return data;
|
||||
}
|
||||
|
||||
bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data)
|
||||
{
|
||||
return I2C_writeRegBuf(devId, regAddr, &data, 1);
|
||||
}
|
||||
102
arm9/source/i2c.h
Normal file
102
arm9/source/i2c.h
Normal file
@@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* This file is part of fastboot 3DS
|
||||
* Copyright (C) 2017 derrek, profi200
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "types.h"
|
||||
|
||||
|
||||
#define I2C_STOP (1u)
|
||||
#define I2C_START (1u<<1)
|
||||
#define I2C_ERROR (1u<<2)
|
||||
#define I2C_ACK (1u<<4)
|
||||
#define I2C_DIRE_WRITE (0u)
|
||||
#define I2C_DIRE_READ (1u<<5)
|
||||
#define I2C_IRQ_ENABLE (1u<<6)
|
||||
#define I2C_ENABLE (1u<<7)
|
||||
|
||||
#define I2C_GET_ACK(reg) ((bool)((reg)>>4 & 1u))
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
I2C_DEV_POWER = 0, // Unconfirmed
|
||||
I2C_DEV_CAMERA = 1, // Unconfirmed
|
||||
I2C_DEV_CAMERA2 = 2, // Unconfirmed
|
||||
I2C_DEV_MCU = 3,
|
||||
I2C_DEV_GYRO = 10,
|
||||
I2C_DEV_DEBUG_PAD = 12,
|
||||
I2C_DEV_IR = 13,
|
||||
I2C_DEV_EEPROM = 14, // Unconfirmed
|
||||
I2C_DEV_NFC = 15,
|
||||
I2C_DEV_QTM = 16,
|
||||
I2C_DEV_N3DS_HID = 17
|
||||
} I2cDevice;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes the I2C buses. Call this only once.
|
||||
*/
|
||||
void I2C_init(void);
|
||||
|
||||
/**
|
||||
* @brief Reads data from a I2C register to a buffer.
|
||||
*
|
||||
* @param[in] devId The device ID. Use the enum above.
|
||||
* @param[in] regAddr The register address.
|
||||
* @param out The output buffer pointer.
|
||||
* @param[in] size The read size.
|
||||
*
|
||||
* @return Returns true on success and false on failure.
|
||||
*/
|
||||
bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size);
|
||||
|
||||
/**
|
||||
* @brief Writes a buffer to a I2C register.
|
||||
*
|
||||
* @param[in] devId The device ID. Use the enum above.
|
||||
* @param[in] regAddr The register address.
|
||||
* @param[in] in The input buffer pointer.
|
||||
* @param[in] size The write size.
|
||||
*
|
||||
* @return Returns true on success and false on failure.
|
||||
*/
|
||||
bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size);
|
||||
|
||||
/**
|
||||
* @brief Reads a byte from a I2C register.
|
||||
*
|
||||
* @param[in] devId The device ID. Use the enum above.
|
||||
* @param[in] regAddr The register address.
|
||||
*
|
||||
* @return Returns the value read on success otherwise 0xFF.
|
||||
*/
|
||||
u8 I2C_readReg(I2cDevice devId, u8 regAddr);
|
||||
|
||||
/**
|
||||
* @brief Writes a byte to a I2C register.
|
||||
*
|
||||
* @param[in] devId The device ID. Use the enum above.
|
||||
* @param[in] regAddr The register address.
|
||||
* @param[in] data The data to write.
|
||||
*
|
||||
* @return Returns true on success and false on failure.
|
||||
*/
|
||||
bool I2C_writeReg(I2cDevice devId, u8 regAddr, u8 data);
|
||||
38
arm9/source/large_patches.h
Normal file
38
arm9/source/large_patches.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
extern const u8 emunandPatch[];
|
||||
extern const u32 emunandPatchSize;
|
||||
extern u32 emunandPatchSdmmcStructPtr, emunandPatchNandOffset, emunandPatchNcsdHeaderOffset;
|
||||
|
||||
extern const u8 rebootPatch[];
|
||||
extern const u32 rebootPatchSize;
|
||||
extern u32 rebootPatchFopenPtr;
|
||||
extern u16 rebootPatchFileName[80+1];
|
||||
291
arm9/source/large_patches.s
Normal file
291
arm9/source/large_patches.s
Normal file
@@ -0,0 +1,291 @@
|
||||
.section .large_patch.emunand, "aw", %progbits
|
||||
.arm
|
||||
.align 4
|
||||
|
||||
@ Code originally by Normmatt
|
||||
|
||||
.global emunandPatch
|
||||
emunandPatch:
|
||||
@ Original code that still needs to be executed
|
||||
mov r4, r0
|
||||
mov r5, r1
|
||||
mov r7, r2
|
||||
mov r6, r3
|
||||
@ End
|
||||
|
||||
@ If we're already trying to access the SD, return
|
||||
ldr r2, [r0, #4]
|
||||
ldr r1, emunandPatchSdmmcStructPtr
|
||||
cmp r2, r1
|
||||
beq out
|
||||
|
||||
str r1, [r0, #4] @ Set object to be SD
|
||||
ldr r2, [r0, #8] @ Get sector to read
|
||||
cmp r2, #0 @ For GW compatibility, see if we're trying to read the ncsd header (sector 0)
|
||||
|
||||
ldr r3, emunandPatchNandOffset
|
||||
add r2, r3 @ Add the offset to the NAND in the SD
|
||||
|
||||
ldreq r3, emunandPatchNcsdHeaderOffset
|
||||
addeq r2, r3 @ If we're reading the ncsd header, add the offset of that sector
|
||||
|
||||
str r2, [r0, #8] @ Store sector to read
|
||||
|
||||
out:
|
||||
@ Restore registers.
|
||||
mov r1, r5
|
||||
mov r2, r7
|
||||
mov r3, r6
|
||||
|
||||
@ Return 4 bytes behind where we got called,
|
||||
@ due to the offset of this function being stored there
|
||||
mov r0, lr
|
||||
add r0, #4
|
||||
bx r0
|
||||
|
||||
.pool
|
||||
|
||||
.global emunandPatchSdmmcStructPtr
|
||||
.global emunandPatchNandOffset
|
||||
.global emunandPatchNcsdHeaderOffset
|
||||
|
||||
emunandPatchSdmmcStructPtr: .word 0 @ Pointer to sdmmc struct
|
||||
emunandPatchNandOffset: .word 0 @ For rednand this should be 1
|
||||
emunandPatchNcsdHeaderOffset: .word 0 @ Depends on nand manufacturer + emunand type (GW/RED)
|
||||
|
||||
.pool
|
||||
.balign 4
|
||||
|
||||
_emunandPatchEnd:
|
||||
|
||||
.global emunandPatchSize
|
||||
emunandPatchSize:
|
||||
.word _emunandPatchEnd - emunandPatch
|
||||
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
@ Code originally from delebile and mid-kid
|
||||
|
||||
.section .large_patch.reboot, "aw", %progbits
|
||||
.arm
|
||||
.align 4
|
||||
|
||||
#define copy_launch_stub_stack_top 0x01FFB800
|
||||
#define copy_launch_stub_stack_bottom 0x01FFA800
|
||||
#define copy_launch_stub_addr 0x01FF9000
|
||||
|
||||
#define argv_addr (copy_launch_stub_stack_bottom - 0x100)
|
||||
#define fname_addr (copy_launch_stub_stack_bottom - 0x200)
|
||||
#define low_tid_addr (copy_launch_stub_stack_bottom - 0x300)
|
||||
|
||||
#define firm_addr 0x20001000
|
||||
#define firm_maxsize 0x07FFF000
|
||||
|
||||
.global rebootPatch
|
||||
rebootPatch:
|
||||
@ Interesting registers and locations to keep in mind, set just before this code is ran:
|
||||
@ - r1: FIRM path in exefs.
|
||||
@ - r7 (or r8): pointer to file object
|
||||
@ - *r7: vtable
|
||||
@ - *(vtable + 0x28): fread function
|
||||
@ - *(r7 + 8): file handle
|
||||
|
||||
sub r7, r0, #8
|
||||
mov r8, r1
|
||||
|
||||
pxi_wait_recv:
|
||||
ldr r2, =0x44846
|
||||
ldr r0, =0x10008000
|
||||
readPxiLoop1:
|
||||
ldrh r1, [r0, #4]
|
||||
lsls r1, #0x17
|
||||
bmi readPxiLoop1
|
||||
ldr r0, [r0, #0xC]
|
||||
cmp r0, r2
|
||||
bne pxi_wait_recv
|
||||
|
||||
@ Open file
|
||||
add r0, r7, #8
|
||||
adr r1, rebootPatchFileName
|
||||
mov r2, #1
|
||||
adr r6, rebootPatchFopenPtr
|
||||
ldr r6, [r6]
|
||||
orr r6, #1
|
||||
blx r6
|
||||
cmp r0, #0
|
||||
bne panic
|
||||
|
||||
@ Read file
|
||||
mov r0, r7
|
||||
adr r1, bytes_read
|
||||
ldr r2, =firm_addr
|
||||
ldr r3, =firm_maxsize
|
||||
ldr r6, [r7]
|
||||
ldr r6, [r6, #0x28]
|
||||
blx r6
|
||||
|
||||
@ Copy the low TID (in UTF-16) of the wanted firm
|
||||
ldr r0, =low_tid_addr
|
||||
add r1, r8, #0x1A
|
||||
mov r2, #0x10
|
||||
bl memcpy16
|
||||
|
||||
@ Copy argv[0]
|
||||
ldr r0, =fname_addr
|
||||
adr r1, rebootPatchFileName
|
||||
mov r2, #82
|
||||
bl memcpy16
|
||||
|
||||
ldr r0, =argv_addr
|
||||
ldr r1, =fname_addr
|
||||
ldr r2, =low_tid_addr
|
||||
stmia r0, {r1, r2}
|
||||
|
||||
@ Set kernel state
|
||||
mov r0, #0
|
||||
mov r1, #0
|
||||
mov r2, #0
|
||||
mov r3, #0
|
||||
svc 0x7C
|
||||
|
||||
goto_reboot:
|
||||
@ Jump to reboot code
|
||||
ldr r0, kernel_func_displ
|
||||
add r0, pc @ pc is two instructions ahead of the instruction being executed (12 = 2*4 + 4)
|
||||
svc 0x7B
|
||||
|
||||
die:
|
||||
b die
|
||||
|
||||
memcpy16:
|
||||
cmp r2, #0
|
||||
bxeq lr
|
||||
add r2, r0, r2
|
||||
copy_loop16:
|
||||
ldrh r3, [r1], #2
|
||||
strh r3, [r0], #2
|
||||
cmp r0, r2
|
||||
blo copy_loop16
|
||||
bx lr
|
||||
|
||||
panic:
|
||||
mov r1, r0 @ unused register
|
||||
mov r0, #0
|
||||
svc 0x3C @ svcBreak(USERBREAK_PANIC)
|
||||
b die
|
||||
|
||||
kernel_func_displ:
|
||||
.word kernelcode_start - goto_reboot - 12
|
||||
|
||||
bytes_read:
|
||||
.word 0
|
||||
|
||||
.global rebootPatchFopenPtr
|
||||
rebootPatchFopenPtr:
|
||||
.word 0
|
||||
|
||||
.pool
|
||||
|
||||
.global rebootPatchFileName
|
||||
rebootPatchFileName:
|
||||
.skip 2*(80+1)
|
||||
|
||||
.balign 4
|
||||
kernelcode_start:
|
||||
|
||||
msr cpsr_cxsf, #0xD3 @ disable interrupts and clear flags
|
||||
|
||||
ldr sp, =copy_launch_stub_stack_top
|
||||
|
||||
ldr r0, =copy_launch_stub_addr
|
||||
adr r1, copy_launch_stub
|
||||
mov r2, #(copy_launch_stub_end - copy_launch_stub)
|
||||
bl memcpy32
|
||||
|
||||
@ Disable MPU
|
||||
ldr r0, =0x42078 @ alt vector select, enable itcm
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
bl flushCaches
|
||||
|
||||
ldr r0, =copy_launch_stub_addr
|
||||
bx r0
|
||||
|
||||
copy_launch_stub:
|
||||
|
||||
ldr r4, =firm_addr
|
||||
|
||||
mov r5, #0
|
||||
load_section_loop:
|
||||
@ Such checks. Very ghetto. Wow.
|
||||
add r3, r4, #0x40
|
||||
add r3, r5,lsl #5
|
||||
add r3, r5,lsl #4
|
||||
ldmia r3, {r6-r8}
|
||||
cmp r8, #0
|
||||
movne r0, r7
|
||||
addne r1, r4, r6
|
||||
movne r2, r8
|
||||
blne memcpy32
|
||||
add r5, #1
|
||||
cmp r5, #4
|
||||
blo load_section_loop
|
||||
|
||||
mov r0, #2 @ argc
|
||||
ldr r1, =argv_addr @ argv
|
||||
ldr r2, =0xBABE @ magic word
|
||||
|
||||
mov r5, #0x20000000
|
||||
ldr r6, [r4, #0x08]
|
||||
str r6, [r5, #-4] @ store arm11 entrypoint
|
||||
|
||||
ldr lr, [r4, #0x0c]
|
||||
bx lr
|
||||
|
||||
memcpy32:
|
||||
add r2, r0, r2
|
||||
copy_loop32:
|
||||
ldr r3, [r1], #4
|
||||
str r3, [r0], #4
|
||||
cmp r0, r2
|
||||
blo copy_loop32
|
||||
bx lr
|
||||
|
||||
.pool
|
||||
|
||||
copy_launch_stub_end:
|
||||
|
||||
flushCaches:
|
||||
|
||||
@ Clean and flush data cache
|
||||
mov r1, #0 @ segment counter
|
||||
outer_loop:
|
||||
mov r0, #0 @ line counter
|
||||
|
||||
inner_loop:
|
||||
orr r2, r1, r0 @ generate segment and line address
|
||||
mcr p15, 0, r2, c7, c14, 2 @ clean and flush the line
|
||||
add r0, #0x20 @ increment to next line
|
||||
cmp r0, #0x400
|
||||
bne inner_loop
|
||||
|
||||
add r1, #0x40000000
|
||||
cmp r1, #0
|
||||
bne outer_loop
|
||||
|
||||
@ Drain write buffer
|
||||
mcr p15, 0, r1, c7, c10, 4
|
||||
|
||||
@ Flush instruction cache
|
||||
mcr p15, 0, r1, c7, c5, 0
|
||||
|
||||
bx lr
|
||||
|
||||
.pool
|
||||
.balign 4
|
||||
|
||||
_rebootPatchEnd:
|
||||
|
||||
.global rebootPatchSize
|
||||
rebootPatchSize:
|
||||
.word _rebootPatchEnd - rebootPatch
|
||||
388
arm9/source/main.c
Normal file
388
arm9/source/main.c
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "emunand.h"
|
||||
#include "fs.h"
|
||||
#include "firm.h"
|
||||
#include "utils.h"
|
||||
#include "exceptions.h"
|
||||
#include "draw.h"
|
||||
#include "buttons.h"
|
||||
#include "pin.h"
|
||||
#include "crypto.h"
|
||||
#include "memory.h"
|
||||
#include "screen.h"
|
||||
#include "i2c.h"
|
||||
#include "fatfs/sdmmc/sdmmc.h"
|
||||
|
||||
extern u8 __itcm_start__[], __itcm_lma__[], __itcm_bss_start__[], __itcm_end__[];
|
||||
|
||||
extern CfgData configData;
|
||||
extern ConfigurationStatus needConfig;
|
||||
extern FirmwareSource firmSource;
|
||||
|
||||
bool isSdMode;
|
||||
u16 launchedPath[80+1];
|
||||
BootType bootType;
|
||||
|
||||
void main(int argc, char **argv, u32 magicWord)
|
||||
{
|
||||
bool isFirmProtEnabled,
|
||||
isSafeMode = false,
|
||||
needToInitSd = false,
|
||||
isNoForceFlagSet = false,
|
||||
isInvalidLoader = false,
|
||||
isNtrBoot;
|
||||
FirmwareType firmType;
|
||||
FirmwareSource nandType;
|
||||
const vu8 *bootMediaStatus = (const vu8 *)0x1FFFE00C;
|
||||
const vu32 *bootPartitionsStatus = (const vu32 *)0x1FFFE010;
|
||||
u32 firmlaunchTidLow = 0;
|
||||
|
||||
//Shell closed, no error booting NTRCARD, NAND paritions not even considered
|
||||
isNtrBoot = bootMediaStatus[3] == 2 && !bootMediaStatus[1] && !bootPartitionsStatus[0] && !bootPartitionsStatus[1];
|
||||
|
||||
if((magicWord & 0xFFFF) == 0xBEEF && argc >= 1) //Normal (B9S) boot
|
||||
{
|
||||
bootType = isNtrBoot ? B9SNTR : B9S;
|
||||
|
||||
u32 i;
|
||||
for(i = 0; i < sizeof(launchedPath)/2 - 1 && argv[0][i] != 0; i++) //Copy and convert the path to UTF-16
|
||||
launchedPath[i] = argv[0][i];
|
||||
launchedPath[i] = 0;
|
||||
}
|
||||
else if(magicWord == 0xBABE && argc == 2) //Firmlaunch
|
||||
{
|
||||
bootType = FIRMLAUNCH;
|
||||
|
||||
u32 i;
|
||||
u16 *p = (u16 *)argv[0];
|
||||
for(i = 0; i < sizeof(launchedPath)/2 - 1 && p[i] != 0; i++)
|
||||
launchedPath[i] = p[i];
|
||||
launchedPath[i] = 0;
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
firmlaunchTidLow = (argv[1][2 * i] > '9' ? argv[1][2 * i] - 'a' + 10 : argv[1][2 * i] - '0') | (firmlaunchTidLow << 4);
|
||||
}
|
||||
else if(magicWord == 0xB002) //FIRM/NTRCARD boot
|
||||
{
|
||||
if(isNtrBoot) bootType = NTR;
|
||||
else
|
||||
{
|
||||
const char *path;
|
||||
if(!((vu8 *)bootPartitionsStatus)[2])
|
||||
{
|
||||
bootType = FIRM0;
|
||||
path = "firm0:";
|
||||
}
|
||||
else
|
||||
{
|
||||
bootType = FIRM1;
|
||||
path = "firm1:";
|
||||
}
|
||||
|
||||
for(u32 i = 0; i < 7; i++) //Copy and convert the path to UTF-16
|
||||
launchedPath[i] = path[i];
|
||||
}
|
||||
|
||||
setupKeyslots();
|
||||
}
|
||||
else isInvalidLoader = true;
|
||||
|
||||
// Set up the additional sections, overwrites argc
|
||||
memcpy(__itcm_start__, __itcm_lma__, __itcm_bss_start__ - __itcm_start__);
|
||||
memset(__itcm_bss_start__, 0, __itcm_end__ - __itcm_bss_start__);
|
||||
I2C_init();
|
||||
if(isInvalidLoader) error("Launched using an unsupported loader.");
|
||||
|
||||
installArm9Handlers();
|
||||
|
||||
if(memcmp(launchedPath, u"sdmc", 8) == 0)
|
||||
{
|
||||
if(!mountFs(true, false)) error("Failed to mount SD.");
|
||||
isSdMode = true;
|
||||
}
|
||||
else if(memcmp(launchedPath, u"nand", 8) == 0)
|
||||
{
|
||||
if(!mountFs(false, true)) error("Failed to mount CTRNAND.");
|
||||
isSdMode = false;
|
||||
}
|
||||
else if(bootType == NTR || memcmp(launchedPath, u"firm", 8) == 0)
|
||||
{
|
||||
if(mountFs(true, false)) isSdMode = true;
|
||||
else if(mountFs(false, true)) isSdMode = false;
|
||||
else error("Failed to mount SD and CTRNAND.");
|
||||
|
||||
if(bootType == NTR)
|
||||
{
|
||||
while(HID_PAD & NTRBOOT_BUTTONS);
|
||||
loadHomebrewFirm(0);
|
||||
mcuPowerOff();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char mountPoint[5];
|
||||
|
||||
u32 i;
|
||||
for(i = 0; i < 4 && launchedPath[i] != u':'; i++)
|
||||
mountPoint[i] = (char)launchedPath[i];
|
||||
mountPoint[i] = 0;
|
||||
|
||||
error("Launched from an unsupported location: %s.", mountPoint);
|
||||
}
|
||||
|
||||
detectAndProcessExceptionDumps();
|
||||
|
||||
//Attempt to read the configuration file
|
||||
needConfig = readConfig() ? MODIFY_CONFIGURATION : CREATE_CONFIGURATION;
|
||||
|
||||
//Determine if this is a firmlaunch boot
|
||||
if(bootType == FIRMLAUNCH)
|
||||
{
|
||||
if(needConfig == CREATE_CONFIGURATION) mcuPowerOff();
|
||||
|
||||
switch(firmlaunchTidLow & 0xF)
|
||||
{
|
||||
case 2:
|
||||
firmType = (FirmwareType)((firmlaunchTidLow >> 8) & 0xF);
|
||||
break;
|
||||
case 3:
|
||||
firmType = SAFE_FIRM;
|
||||
break;
|
||||
case 1:
|
||||
firmType = SYSUPDATER_FIRM;
|
||||
break;
|
||||
}
|
||||
|
||||
nandType = (FirmwareSource)BOOTCFG_NAND;
|
||||
firmSource = (FirmwareSource)BOOTCFG_FIRM;
|
||||
isFirmProtEnabled = !BOOTCFG_NTRCARDBOOT;
|
||||
|
||||
goto boot;
|
||||
}
|
||||
|
||||
firmType = NATIVE_FIRM;
|
||||
isFirmProtEnabled = bootType != NTR;
|
||||
|
||||
//Get pressed buttons
|
||||
u32 pressed = HID_PAD;
|
||||
|
||||
//If it's a MCU reboot, try to force boot options
|
||||
if(CFG_BOOTENV && needConfig != CREATE_CONFIGURATION)
|
||||
{
|
||||
//Always force a SysNAND boot when quitting AGB_FIRM
|
||||
if(CFG_BOOTENV == 7)
|
||||
{
|
||||
nandType = FIRMWARE_SYSNAND;
|
||||
firmSource = (BOOTCFG_NAND != 0) == (BOOTCFG_FIRM != 0) ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM;
|
||||
|
||||
//Prevent multiple boot options-forcing
|
||||
if(nandType != BOOTCFG_NAND || firmSource != BOOTCFG_FIRM) isNoForceFlagSet = true;
|
||||
|
||||
goto boot;
|
||||
}
|
||||
|
||||
//Account for DSiWare soft resets if exiting TWL_FIRM
|
||||
if(CFG_BOOTENV == 3)
|
||||
{
|
||||
static const u8 TLNC[] = {0x54, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x43};
|
||||
if(memcmp((void *)0x20000C00, TLNC, 10) == 0) needToInitSd = true;
|
||||
}
|
||||
|
||||
/* Force the last used boot options if autobooting a TWL title, or unless a button is pressed
|
||||
or the no-forcing flag is set */
|
||||
if(needToInitSd || memcmp((void *)0x20000300, "TLNC", 4) == 0 || (!pressed && !BOOTCFG_NOFORCEFLAG))
|
||||
{
|
||||
nandType = (FirmwareSource)BOOTCFG_NAND;
|
||||
firmSource = (FirmwareSource)BOOTCFG_FIRM;
|
||||
|
||||
goto boot;
|
||||
}
|
||||
}
|
||||
|
||||
u32 pinMode = MULTICONFIG(PIN);
|
||||
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT);
|
||||
bool pinExists = pinMode != 0 && verifyPin(pinMode);
|
||||
|
||||
/* If the PIN has been verified, wait to make it easier to press the SAFE_MODE combo or the configuration menu button
|
||||
(if not already pressed, for the latter) */
|
||||
if(pinExists && !shouldLoadConfigMenu)
|
||||
{
|
||||
while(HID_PAD & PIN_BUTTONS);
|
||||
wait(2000ULL);
|
||||
|
||||
//Update pressed buttons
|
||||
pressed = HID_PAD;
|
||||
}
|
||||
|
||||
shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & (BUTTON_SELECT | BUTTON_L1)) == BUTTON_SELECT);
|
||||
if(shouldLoadConfigMenu)
|
||||
{
|
||||
configMenu(pinExists, pinMode);
|
||||
|
||||
//Update pressed buttons
|
||||
pressed = HID_PAD;
|
||||
}
|
||||
|
||||
if(!CFG_BOOTENV && pressed == SAFE_MODE)
|
||||
{
|
||||
nandType = FIRMWARE_SYSNAND;
|
||||
firmSource = FIRMWARE_SYSNAND;
|
||||
|
||||
isSafeMode = true;
|
||||
needToInitSd = true;
|
||||
|
||||
goto boot;
|
||||
}
|
||||
|
||||
u32 splashMode = MULTICONFIG(SPLASH);
|
||||
|
||||
if(splashMode == 1 && loadSplash()) pressed = HID_PAD;
|
||||
|
||||
bool autoBootEmu = CONFIG(AUTOBOOTEMU);
|
||||
|
||||
if((pressed & (BUTTON_START | BUTTON_L1)) == BUTTON_START)
|
||||
{
|
||||
loadHomebrewFirm(0);
|
||||
pressed = HID_PAD;
|
||||
}
|
||||
else if((((pressed & SINGLE_PAYLOAD_BUTTONS) || (!autoBootEmu && (pressed & DPAD_BUTTONS))) && !(pressed & (BUTTON_L1 | BUTTON_R1))) ||
|
||||
(((pressed & L_PAYLOAD_BUTTONS) || (autoBootEmu && (pressed & DPAD_BUTTONS))) && (pressed & BUTTON_L1))) loadHomebrewFirm(pressed);
|
||||
|
||||
if(splashMode == 2 && loadSplash()) pressed = HID_PAD;
|
||||
|
||||
//Check SAFE_MODE combo again
|
||||
if(!CFG_BOOTENV && pressed == SAFE_MODE)
|
||||
{
|
||||
nandType = FIRMWARE_SYSNAND;
|
||||
firmSource = FIRMWARE_SYSNAND;
|
||||
|
||||
isSafeMode = true;
|
||||
needToInitSd = true;
|
||||
|
||||
goto boot;
|
||||
}
|
||||
|
||||
//If booting from CTRNAND, always use SysNAND
|
||||
if(!isSdMode) nandType = FIRMWARE_SYSNAND;
|
||||
|
||||
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
|
||||
else if(pressed & BUTTON_R1)
|
||||
{
|
||||
if(CONFIG(USEEMUFIRM))
|
||||
{
|
||||
nandType = FIRMWARE_SYSNAND;
|
||||
firmSource = FIRMWARE_EMUNAND;
|
||||
}
|
||||
else
|
||||
{
|
||||
nandType = FIRMWARE_EMUNAND;
|
||||
firmSource = FIRMWARE_SYSNAND;
|
||||
}
|
||||
}
|
||||
|
||||
/* Else, boot the NAND the user set to autoboot or the opposite one, depending on L,
|
||||
with their own FIRM */
|
||||
else firmSource = nandType = (autoBootEmu == ((pressed & BUTTON_L1) == BUTTON_L1)) ? FIRMWARE_SYSNAND : FIRMWARE_EMUNAND;
|
||||
|
||||
//If we're booting EmuNAND or using EmuNAND FIRM, determine which one from the directional pad buttons, or otherwise from the config
|
||||
if(nandType == FIRMWARE_EMUNAND || firmSource == FIRMWARE_EMUNAND)
|
||||
{
|
||||
FirmwareSource tempNand;
|
||||
switch(pressed & DPAD_BUTTONS)
|
||||
{
|
||||
case BUTTON_UP:
|
||||
tempNand = FIRMWARE_EMUNAND;
|
||||
break;
|
||||
case BUTTON_RIGHT:
|
||||
tempNand = FIRMWARE_EMUNAND2;
|
||||
break;
|
||||
case BUTTON_DOWN:
|
||||
tempNand = FIRMWARE_EMUNAND3;
|
||||
break;
|
||||
case BUTTON_LEFT:
|
||||
tempNand = FIRMWARE_EMUNAND4;
|
||||
break;
|
||||
default:
|
||||
tempNand = (FirmwareSource)(1 + MULTICONFIG(DEFAULTEMU));
|
||||
break;
|
||||
}
|
||||
|
||||
if(nandType == FIRMWARE_EMUNAND) nandType = tempNand;
|
||||
else firmSource = tempNand;
|
||||
}
|
||||
|
||||
boot:
|
||||
|
||||
//If we need to boot EmuNAND, make sure it exists
|
||||
if(nandType != FIRMWARE_SYSNAND)
|
||||
{
|
||||
locateEmuNand(&nandType);
|
||||
if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND;
|
||||
else if((*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) //Make sure the SD card isn't write protected
|
||||
error("The SD card is locked, EmuNAND can not be used.\nPlease turn the write protection switch off.");
|
||||
}
|
||||
|
||||
//Same if we're using EmuNAND as the FIRM source
|
||||
else if(firmSource != FIRMWARE_SYSNAND)
|
||||
locateEmuNand(&firmSource);
|
||||
|
||||
if(bootType != FIRMLAUNCH)
|
||||
{
|
||||
configData.bootConfig = ((bootType == NTR ? 1 : 0) << 7) | ((u32)isNoForceFlagSet << 6) | ((u32)firmSource << 3) | (u32)nandType;
|
||||
writeConfig(false);
|
||||
}
|
||||
|
||||
bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES);
|
||||
u32 firmVersion = loadNintendoFirm(&firmType, firmSource, loadFromStorage, isSafeMode);
|
||||
|
||||
bool doUnitinfoPatch = CONFIG(PATCHUNITINFO);
|
||||
u32 res = 0;
|
||||
switch(firmType)
|
||||
{
|
||||
case NATIVE_FIRM:
|
||||
res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isFirmProtEnabled, needToInitSd, doUnitinfoPatch);
|
||||
break;
|
||||
case TWL_FIRM:
|
||||
res = patchTwlFirm(firmVersion, loadFromStorage, doUnitinfoPatch);
|
||||
break;
|
||||
case AGB_FIRM:
|
||||
res = patchAgbFirm(loadFromStorage, doUnitinfoPatch);
|
||||
break;
|
||||
case SAFE_FIRM:
|
||||
case SYSUPDATER_FIRM:
|
||||
case NATIVE_FIRM1X2X:
|
||||
res = patch1x2xNativeAndSafeFirm();
|
||||
break;
|
||||
}
|
||||
|
||||
if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
|
||||
|
||||
if(bootType != FIRMLAUNCH) deinitScreens();
|
||||
launchFirm(0, NULL);
|
||||
}
|
||||
56
arm9/source/memory.c
Normal file
56
arm9/source/memory.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Boyer-Moore Horspool algorithm adapted from http://www-igm.univ-mlv.fr/~lecroq/string/node18.html#SECTION00180
|
||||
* memcpy, memset and memcmp adapted from https://github.com/mid-kid/CakesForeveryWan/blob/557a8e8605ab3ee173af6497486e8f22c261d0e2/source/memfuncs.c
|
||||
*/
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
|
||||
{
|
||||
const u8 *patternc = (const u8 *)pattern;
|
||||
u32 table[256];
|
||||
|
||||
//Preprocessing
|
||||
for(u32 i = 0; i < 256; i++)
|
||||
table[i] = patternSize;
|
||||
for(u32 i = 0; i < patternSize - 1; i++)
|
||||
table[patternc[i]] = patternSize - i - 1;
|
||||
|
||||
//Searching
|
||||
u32 j = 0;
|
||||
while(j <= size - patternSize)
|
||||
{
|
||||
u8 c = startPos[j + patternSize - 1];
|
||||
if(patternc[patternSize - 1] == c && memcmp(pattern, startPos + j, patternSize - 1) == 0)
|
||||
return startPos + j;
|
||||
j += table[c];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
36
arm9/source/memory.h
Normal file
36
arm9/source/memory.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Boyer-Moore Horspool algorithm adapted from http://www-igm.univ-mlv.fr/~lecroq/string/node18.html#SECTION00180
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
#include "types.h"
|
||||
|
||||
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize);
|
||||
705
arm9/source/patches.c
Normal file
705
arm9/source/patches.c
Normal file
@@ -0,0 +1,705 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Signature patches by an unknown author
|
||||
* Signature patches for old FIRMs by SciresM
|
||||
* firmlaunches patching code originally by delebile
|
||||
* FIRM partition writes patches by delebile
|
||||
* Idea for svcBreak patches from yellows8 and others on #3dsdev
|
||||
* TWL_FIRM patches by Steveice10 and others
|
||||
*/
|
||||
|
||||
#include "patches.h"
|
||||
#include "fs.h"
|
||||
#include "exceptions.h"
|
||||
#include "memory.h"
|
||||
#include "config.h"
|
||||
#include "utils.h"
|
||||
#include "arm9_exception_handlers.h"
|
||||
#include "large_patches.h"
|
||||
|
||||
#define K11EXT_VA 0x70000000
|
||||
|
||||
u8 *getProcess9Info(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr)
|
||||
{
|
||||
u8 *temp = memsearch(pos, "NCCH", size, 4);
|
||||
|
||||
if(temp == NULL) error("Failed to get Process9 data.");
|
||||
|
||||
Cxi *off = (Cxi *)(temp - 0x100);
|
||||
|
||||
*process9Size = (off->ncch.exeFsSize - 1) * 0x200;
|
||||
*process9MemAddr = off->exHeader.systemControlInfo.textCodeSet.address;
|
||||
|
||||
return (u8 *)off + (off->ncch.exeFsOffset + 1) * 0x200;
|
||||
}
|
||||
|
||||
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage)
|
||||
{
|
||||
static const u8 pattern[] = {0x00, 0xB0, 0x9C, 0xE5};
|
||||
*arm11ExceptionsPage = (u32 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(*arm11ExceptionsPage == NULL) error("Failed to get Kernel11 data.");
|
||||
|
||||
u32 *arm11SvcTable;
|
||||
|
||||
*arm11ExceptionsPage -= 0xB;
|
||||
u32 svcOffset = (-(((*arm11ExceptionsPage)[2] & 0xFFFFFF) << 2) & (0xFFFFFF << 2)) - 8; //Branch offset + 8 for prefetch
|
||||
u32 pointedInstructionVA = 0xFFFF0008 - svcOffset;
|
||||
*baseK11VA = pointedInstructionVA & 0xFFFF0000; //This assumes that the pointed instruction has an offset < 0x10000, iirc that's always the case
|
||||
arm11SvcTable = *arm11SvcHandler = (u32 *)(pos + *(u32 *)(pos + pointedInstructionVA - *baseK11VA + 8) - *baseK11VA); //SVC handler address
|
||||
while(*arm11SvcTable) arm11SvcTable++; //Look for SVC0 (NULL)
|
||||
|
||||
u32 *freeSpace;
|
||||
for(freeSpace = *arm11ExceptionsPage; freeSpace < *arm11ExceptionsPage + 0x400 && *freeSpace != 0xFFFFFFFF; freeSpace++);
|
||||
*freeK11Space = (u8 *) freeSpace;
|
||||
|
||||
return arm11SvcTable;
|
||||
}
|
||||
|
||||
// For Arm prologs in the form of: push {regs} ... sub sp, #off (this obviously doesn't intend to cover all cases)
|
||||
static inline u32 computeArmFrameSize(const u32 *prolog)
|
||||
{
|
||||
const u32 *off;
|
||||
|
||||
for(off = prolog; (*off >> 16) != 0xE92D; off++); // look for stmfd sp! = push
|
||||
u32 nbPushedRegs = 0;
|
||||
for(u32 val = *off & 0xFFFF; val != 0; val >>= 1) // 1 bit = 1 pushed register
|
||||
nbPushedRegs += val & 1;
|
||||
for(; (*off >> 8) != 0xE24DD0; off++); // look for sub sp, #offset
|
||||
u32 localVariablesSpaceSize = *off & 0xFF;
|
||||
|
||||
return 4 * nbPushedRegs + localVariablesSpaceSize;
|
||||
}
|
||||
|
||||
static inline u32 *getKernel11HandlerVAPos(u8 *pos, u32 *arm11ExceptionsPage, u32 baseK11VA, u32 id)
|
||||
{
|
||||
u32 off = ((-((arm11ExceptionsPage[id] & 0xFFFFFF) << 2)) & (0xFFFFFF << 2)) - 8;
|
||||
u32 pointedInstructionVA = 0xFFFF0000 + 4 * id - off;
|
||||
return (u32 *)(pos + pointedInstructionVA - baseK11VA + 8);
|
||||
}
|
||||
|
||||
u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 *arm11ExceptionsPage, u8 **freeK11Space)
|
||||
{
|
||||
//The parameters to be passed on to the kernel ext
|
||||
//Please keep that in sync with the definition in k11_extension/source/main.c
|
||||
struct KExtParameters
|
||||
{
|
||||
u32 basePA;
|
||||
u32 stolenSystemMemRegionSize;
|
||||
void *originalHandlers[4];
|
||||
u32 L1MMUTableAddrs[4];
|
||||
|
||||
volatile bool done;
|
||||
|
||||
struct CfwInfo
|
||||
{
|
||||
char magic[4];
|
||||
|
||||
u8 versionMajor;
|
||||
u8 versionMinor;
|
||||
u8 versionBuild;
|
||||
u8 flags;
|
||||
|
||||
u32 commitHash;
|
||||
|
||||
u16 configFormatVersionMajor, configFormatVersionMinor;
|
||||
u32 config, multiConfig, bootConfig;
|
||||
u64 hbldr3dsxTitleId;
|
||||
u32 rosalinaMenuCombo;
|
||||
} info;
|
||||
};
|
||||
|
||||
static const u8 patternHook1[] = {0x02, 0xC2, 0xA0, 0xE3, 0xFF}; //MMU setup hook
|
||||
static const u8 patternHook2[] = {0x08, 0x00, 0xA4, 0xE5, 0x02, 0x10, 0x80, 0xE0, 0x08, 0x10, 0x84, 0xE5}; //FCRAM layout setup hook
|
||||
static const u8 patternHook3_4[] = {0x00, 0x00, 0xA0, 0xE1, 0x03, 0xF0, 0x20, 0xE3, 0xFD, 0xFF, 0xFF, 0xEA}; //SGI0 setup code, etc.
|
||||
|
||||
//Our kernel11 extension is initially loaded in VRAM
|
||||
u32 kextTotalSize = *(u32 *)0x18000020 - K11EXT_VA;
|
||||
u32 stolenSystemMemRegionSize = kextTotalSize; // no need to steal any more mem on N3DS. Currently, everything fits in BASE on O3DS too (?)
|
||||
u32 dstKextPA = (ISN3DS ? 0x2E000000 : 0x26C00000) - stolenSystemMemRegionSize; // start of BASE memregion (note: linear heap ---> <--- the rest)
|
||||
|
||||
u32 *hookVeneers = (u32 *)*freeK11Space;
|
||||
u32 relocBase = 0xFFFF0000 + (*freeK11Space - (u8 *)arm11ExceptionsPage);
|
||||
|
||||
hookVeneers[0] = 0xE51FF004; //ldr pc, [pc, #-8+4]
|
||||
hookVeneers[1] = 0x18000004;
|
||||
hookVeneers[2] = 0xE51FF004;
|
||||
hookVeneers[3] = K11EXT_VA;
|
||||
hookVeneers[4] = 0xE51FF004;
|
||||
hookVeneers[5] = K11EXT_VA + 8;
|
||||
hookVeneers[6] = 0xE51FF004;
|
||||
hookVeneers[7] = K11EXT_VA + 0xC;
|
||||
|
||||
(*freeK11Space) += 32;
|
||||
|
||||
//MMU setup hook
|
||||
u32 *off = (u32 *)memsearch(pos, patternHook1, size, sizeof(patternHook1));
|
||||
if(off == NULL) return 1;
|
||||
*off = MAKE_BRANCH_LINK(off, hookVeneers);
|
||||
|
||||
//Most important hook: FCRAM layout setup hook
|
||||
off = (u32 *)memsearch(pos, patternHook2, size, sizeof(patternHook2));
|
||||
if(off == NULL) return 1;
|
||||
off += 2;
|
||||
*off = MAKE_BRANCH_LINK(baseK11VA + ((u8 *)off - pos), relocBase + 8);
|
||||
|
||||
//Bind SGI0 hook
|
||||
//Look for cpsie i and place our hook in the nop 2 instructions before
|
||||
off = (u32 *)memsearch(pos, patternHook3_4, size, 12);
|
||||
if(off == NULL) return 1;
|
||||
for(; *off != 0xF1080080; off--);
|
||||
off -= 2;
|
||||
*off = MAKE_BRANCH_LINK(baseK11VA + ((u8 *)off - pos), relocBase + 16);
|
||||
|
||||
//Config hook (after the configuration memory fields have been filled)
|
||||
for(; *off != 0xE1A00000; off++);
|
||||
off += 4;
|
||||
*off = MAKE_BRANCH_LINK(baseK11VA + ((u8 *)off - pos), relocBase + 24);
|
||||
|
||||
struct KExtParameters *p = (struct KExtParameters *)(*(u32 *)0x18000024 - K11EXT_VA + 0x18000000);
|
||||
p->basePA = dstKextPA;
|
||||
p->done = false;
|
||||
p->stolenSystemMemRegionSize = stolenSystemMemRegionSize;
|
||||
|
||||
for(u32 i = 0; i < 4; i++)
|
||||
{
|
||||
u32 *handlerPos = getKernel11HandlerVAPos(pos, arm11ExceptionsPage, baseK11VA, 1 + i);
|
||||
p->originalHandlers[i] = (void *)*handlerPos;
|
||||
*handlerPos = K11EXT_VA + 0x10 + 4 * i;
|
||||
}
|
||||
|
||||
struct CfwInfo *info = &p->info;
|
||||
memcpy(&info->magic, "LUMA", 4);
|
||||
info->commitHash = COMMIT_HASH;
|
||||
info->configFormatVersionMajor = configData.formatVersionMajor;
|
||||
info->configFormatVersionMinor = configData.formatVersionMinor;
|
||||
info->config = configData.config;
|
||||
info->multiConfig = configData.multiConfig;
|
||||
info->bootConfig = configData.bootConfig;
|
||||
info->hbldr3dsxTitleId = configData.hbldr3dsxTitleId;
|
||||
info->rosalinaMenuCombo = configData.rosalinaMenuCombo;
|
||||
info->versionMajor = VERSION_MAJOR;
|
||||
info->versionMinor = VERSION_MINOR;
|
||||
info->versionBuild = VERSION_BUILD;
|
||||
|
||||
if(ISRELEASE) info->flags = 1;
|
||||
if(ISN3DS) info->flags |= 1 << 4;
|
||||
if(needToInitSd) info->flags |= 1 << 5;
|
||||
if(isSdMode) info->flags |= 1 << 6;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchKernel11(u8 *pos, u32 size, u32 baseK11VA, u32 *arm11SvcTable, u32 *arm11ExceptionsPage)
|
||||
{
|
||||
static const u8 patternKPanic[] = {0x02, 0x0B, 0x44, 0xE2};
|
||||
static const u8 patternKThreadDebugReschedule[] = {0x34, 0x20, 0xD4, 0xE5, 0x00, 0x00, 0x55, 0xE3, 0x80, 0x00, 0xA0, 0x13};
|
||||
|
||||
//Assumption: ControlMemory, DebugActiveProcess and KernelSetState are in the first 0x20000 bytes
|
||||
//Patch ControlMemory
|
||||
u8 *instrPos = pos + (arm11SvcTable[1] + 20 - baseK11VA);
|
||||
s32 displ = (*(u32 *)instrPos & 0xFFFFFF) << 2;
|
||||
displ = (displ << 6) >> 6; // sign extend
|
||||
|
||||
u8 *ControlMemoryPos = instrPos + 8 + displ;
|
||||
u32 *off;
|
||||
|
||||
/*
|
||||
Here we replace currentProcess->processID == 1 by additionnalParameter == 1.
|
||||
This patch should be generic enough to work even on firmware version 5.0.
|
||||
|
||||
It effectively changes the prototype of the ControlMemory function which
|
||||
only caller is the svc 0x01 handler on OFW.
|
||||
*/
|
||||
for(off = (u32 *)ControlMemoryPos; (off[0] & 0xFFF0FFFF) != 0xE3500001 || (off[1] & 0xFFFF0FFF) != 0x13A00000; off++);
|
||||
off -= 2;
|
||||
*off = 0xE59D0000 | (*off & 0x0000F000) | (8 + computeArmFrameSize((u32 *)ControlMemoryPos)); // ldr r0, [sp, #(frameSize + 8)]
|
||||
|
||||
//Patch DebugActiveProcess
|
||||
for(off = (u32 *)(pos + (arm11SvcTable[0x60] - baseK11VA)); *off != 0xE3110001; off++);
|
||||
*off = 0xE3B01001; // tst r1, #1 -> movs r1, #1
|
||||
|
||||
for(off = (u32 *)(pos + (arm11SvcTable[0x7C] - baseK11VA)); off[0] != 0xE5D00001 || off[1] != 0xE3500000; off++);
|
||||
off[2] = 0xE1A00000; // in case 6: beq -> nop
|
||||
|
||||
//Patch kernelpanic
|
||||
off = (u32 *)memsearch(pos, patternKPanic, size, sizeof(patternKPanic));
|
||||
if(off == NULL)
|
||||
return 1;
|
||||
|
||||
off[-6] = 0xE12FFF7E;
|
||||
|
||||
//Redirect enableUserExceptionHandlersForCPUExc (= true)
|
||||
for(off = arm11ExceptionsPage; *off != 0x96007F9; off++);
|
||||
off[1] = K11EXT_VA + 0x28;
|
||||
|
||||
off = (u32 *)memsearch(pos, patternKThreadDebugReschedule, size, sizeof(patternKThreadDebugReschedule));
|
||||
if(off == NULL)
|
||||
return 1;
|
||||
|
||||
off[-5] = 0xE51FF004;
|
||||
off[-4] = K11EXT_VA + 0x2C;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchSignatureChecks(u8 *pos, u32 size)
|
||||
{
|
||||
//Look for signature checks
|
||||
static const u8 pattern[] = {0xC0, 0x1C, 0x76, 0xE7},
|
||||
pattern2[] = {0xB5, 0x22, 0x4D, 0x0C};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
u8 *temp = memsearch(pos, pattern2, size, sizeof(pattern2));
|
||||
|
||||
if(off == NULL || temp == NULL) return 1;
|
||||
|
||||
u16 *off2 = (u16 *)(temp - 1);
|
||||
*off = off2[0] = 0x2000;
|
||||
off2[1] = 0x4770;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchOldSignatureChecks(u8 *pos, u32 size)
|
||||
{
|
||||
// Look for signature checks
|
||||
static const u8 pattern[] = {0xC0, 0x1C, 0xBD, 0xE7},
|
||||
pattern2[] = {0xB5, 0x23, 0x4E, 0x0C};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
u8 *temp = memsearch(pos, pattern2, size, sizeof(pattern2));
|
||||
|
||||
if(off == NULL || temp == NULL) return 1;
|
||||
|
||||
u16 *off2 = (u16 *)(temp - 1);
|
||||
*off = off2[0] = 0x2000;
|
||||
off2[1] = 0x4770;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr)
|
||||
{
|
||||
//Look for firmlaunch code
|
||||
static const u8 pattern[] = {0xE2, 0x20, 0x20, 0x90};
|
||||
|
||||
u32 pathLen;
|
||||
for(pathLen = 0; pathLen < sizeof(launchedPath)/2 && launchedPath[pathLen] != 0; pathLen++);
|
||||
|
||||
if(launchedPath[pathLen] != 0) return 1;
|
||||
|
||||
u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off -= 0x13;
|
||||
|
||||
//Firmlaunch function offset - offset in BLX opcode (A4-16 - Arm DDI 0100E) + 1
|
||||
u32 fOpenOffset = (u32)(off + 9 - (-((*(u32 *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - pos + process9MemAddr);
|
||||
|
||||
//Put the fOpen offset in the right location
|
||||
rebootPatchFopenPtr = fOpenOffset;
|
||||
|
||||
//Copy the launched path
|
||||
memcpy(rebootPatchFileName, launchedPath, 2 * (1 + pathLen));
|
||||
|
||||
//Copy firmlaunch code
|
||||
memcpy(off, rebootPatch, rebootPatchSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchFirmWrites(u8 *pos, u32 size)
|
||||
{
|
||||
//Look for FIRM writing code
|
||||
u8 *off = memsearch(pos, "exe:", size, 4);
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
static const u8 pattern[] = {0x00, 0x28, 0x01, 0xDA};
|
||||
|
||||
u16 *off2 = (u16 *)memsearch(off - 0x100, pattern, 0x100, sizeof(pattern));
|
||||
|
||||
if(off2 == NULL) return 1;
|
||||
|
||||
off2[0] = 0x2000;
|
||||
off2[1] = 0x46C0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchOldFirmWrites(u8 *pos, u32 size)
|
||||
{
|
||||
//Look for FIRM writing code
|
||||
static const u8 pattern[] = {0x04, 0x1E, 0x1D, 0xDB};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[0] = 0x2400;
|
||||
off[1] = 0xE01D;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchTitleInstallMinVersionChecks(u8 *pos, u32 size, u32 firmVersion)
|
||||
{
|
||||
static const u8 pattern[] = {0xFF, 0x00, 0x00, 0x02};
|
||||
|
||||
u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return firmVersion == 0xFFFFFFFF ? 0 : 1;
|
||||
|
||||
off++;
|
||||
|
||||
//Zero out the first TitleID in the list
|
||||
memset(off, 0, 8);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchZeroKeyNcchEncryptionCheck(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x28, 0x2A, 0xD0, 0x08};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL) return 1;
|
||||
|
||||
u16 *off = (u16 *)(temp - 1);
|
||||
*off = 0x2001; //mov r0, #1
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchNandNcchEncryptionCheck(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x07, 0xD1, 0x28, 0x7A};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off--;
|
||||
*off = 0x2001; //mov r0, #1
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchCheckForDevCommonKey(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x03, 0x7C, 0x28, 0x00};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
*off = 0x2301; //mov r3, #1
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchK11ModuleLoading(u32 section0size, u32 modulesSize, u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 moduleLoadingPattern[] = {0xE2, 0x05, 0x00, 0x57},
|
||||
modulePidPattern[] = {0x06, 0xA0, 0xE1, 0xF2}; //GetSystemInfo
|
||||
|
||||
u8 *off = memsearch(pos, moduleLoadingPattern, size, 4);
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[1]++;
|
||||
|
||||
u32 *off32;
|
||||
for(off32 = (u32 *)(off - 3); *off32 != 0xE59F0000; off32++);
|
||||
off32 += 2;
|
||||
off32[1] = off32[0] + modulesSize;
|
||||
for(; *off32 != section0size; off32++);
|
||||
*off32 = ((modulesSize + 0x1FF) >> 9) << 9;
|
||||
|
||||
off = memsearch(pos, modulePidPattern, size, 4);
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[0xB] = 6;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchArm9ExceptionHandlersInstall(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x80, 0xE5, 0x40, 0x1C};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL) return 1;
|
||||
|
||||
u32 *off;
|
||||
|
||||
for(off = (u32 *)(temp - 2); *off != 0xE5801000; off--); //Until str r1, [r0]
|
||||
|
||||
for(u32 r0 = 0x08000000; *off != 0xE3A01040; off++) //Until mov r1, #0x40
|
||||
{
|
||||
//Discard everything that's not str rX, [r0, #imm](!)
|
||||
if((*off & 0xFE5F0000) != 0xE4000000) continue;
|
||||
|
||||
u32 rD = (*off >> 12) & 0xF,
|
||||
offset = (*off & 0xFFF) * ((((*off >> 23) & 1) == 0) ? -1 : 1);
|
||||
bool writeback = ((*off >> 21) & 1) != 0,
|
||||
pre = ((*off >> 24) & 1) != 0;
|
||||
|
||||
u32 addr = r0 + ((pre || !writeback) ? offset : 0);
|
||||
if((addr & 7) != 0 && addr != 0x08000014 && addr != 0x08000004) *off = 0xE1A00000; //nop
|
||||
else *off = 0xE5800000 | (rD << 12) | (addr & 0xFFF); //Preserve IRQ and SVC handlers
|
||||
|
||||
if(!pre) addr += offset;
|
||||
if(writeback) r0 = addr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address)
|
||||
{
|
||||
//Stub svcBreak with "bkpt 65535" so we can debug the panic
|
||||
|
||||
//Look for the svc handler
|
||||
static const u8 pattern[] = {0x00, 0xE0, 0x4F, 0xE1}; //mrs lr, spsr
|
||||
|
||||
u32 *arm9SvcTable = (u32 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(arm9SvcTable == NULL) return 1;
|
||||
|
||||
while(*arm9SvcTable != 0) arm9SvcTable++; //Look for SVC0 (NULL)
|
||||
|
||||
u32 *addr = (u32 *)(pos + arm9SvcTable[0x3C] - kernel9Address);
|
||||
|
||||
/*
|
||||
mov r8, sp
|
||||
bkpt 0xffff
|
||||
*/
|
||||
addr[0] = 0xE1A0800D;
|
||||
addr[1] = 0xE12FFF7F;
|
||||
|
||||
arm9ExceptionHandlerSvcBreakAddress = arm9SvcTable[0x3C]; //BreakPtr
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchKernel9Panic(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x00, 0x20, 0x92, 0x15};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL) return 1;
|
||||
|
||||
u32 *off = (u32 *)(temp - 0x34);
|
||||
*off = 0xE12FFF7E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchP9AccessChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x00, 0x08, 0x49, 0x68};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL) return 1;
|
||||
|
||||
u16 *off = (u16 *)(temp - 3);
|
||||
off[0] = 0x2001; //mov r0, #1
|
||||
off[1] = 0x4770; //bx lr
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchUnitInfoValueSet(u8 *pos, u32 size)
|
||||
{
|
||||
//Look for UNITINFO value being set during kernel sync
|
||||
static const u8 pattern[] = {0x01, 0x10, 0xA0, 0x13};
|
||||
|
||||
u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[0] = ISDEVUNIT ? 0 : 1;
|
||||
off[3] = 0xE3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchP9AMTicketWrapperZeroKeyIV(u8 *pos, u32 size, u32 firmVersion)
|
||||
{
|
||||
static const u8 __rt_memclr_pattern[] = {0x00, 0x20, 0xA0, 0xE3, 0x04, 0x00, 0x51, 0xE3, 0x07, 0x00, 0x00, 0x3A};
|
||||
static const u8 pattern[] = {0x20, 0x21, 0xA6, 0xA8};
|
||||
|
||||
u32 function = (u32)memsearch(pos, __rt_memclr_pattern, size, sizeof(__rt_memclr_pattern));
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(function == 0 || off == NULL) return firmVersion == 0xFFFFFFFF ? 0 : 1;
|
||||
|
||||
//After the found code it's a BL call (at &off[2]), that will be replaced
|
||||
//From Thumb, op distance for setting in BLX can be got with,
|
||||
//(Destination_offset - blx_op_offset+2) / 2
|
||||
s32 opjumpdistance = (s32)(function - ((u32)&off[3])) / 2;
|
||||
|
||||
//Beyond limit
|
||||
if(opjumpdistance < -0x1fffff || opjumpdistance > 0x1fffff) return 1;
|
||||
|
||||
//r0 and r1 for old call are already correct for this one
|
||||
//BLX __rt_memclr
|
||||
u32 op = (0xE800F000U | (((u32)opjumpdistance & 0x7FF) << 16) | (((u32)opjumpdistance >> 11) & 0x3FF) | (((u32)opjumpdistance >> 21) & 0x400)) & ~(1<<16);
|
||||
|
||||
off[2] = op;
|
||||
off[3] = op >> 16;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchLgySignatureChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x47, 0xC1, 0x17, 0x49};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL) return 1;
|
||||
|
||||
u16 *off = (u16 *)(temp + 1);
|
||||
off[0] = 0x2000;
|
||||
off[1] = 0xB04E;
|
||||
off[2] = 0xBD70;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchTwlInvalidSignatureChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x20, 0xF6, 0xE7, 0x7F};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL) return 1;
|
||||
|
||||
u16 *off = (u16 *)(temp - 1);
|
||||
*off = 0x2001; //mov r0, #1
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchTwlNintendoLogoChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0xC0, 0x30, 0x06, 0xF0};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[1] = 0x2000;
|
||||
off[2] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchTwlWhitelistChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x22, 0x00, 0x20, 0x30};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[2] = 0x2000;
|
||||
off[3] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion)
|
||||
{
|
||||
static const u8 pattern[] = {0x25, 0x20, 0x00, 0x0E};
|
||||
|
||||
u8 *temp = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(temp == NULL)
|
||||
{
|
||||
if(firmVersion == 0xFFFFFFFF) return patchOldTwlFlashcartChecks(pos, size);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
u16 *off = (u16 *)(temp + 3);
|
||||
off[0] = off[6] = off[0xC] = 0x2001; //mov r0, #1
|
||||
off[1] = off[7] = off[0xD] = 0; //nop
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x06, 0xF0, 0xA0, 0xFD};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[0] = off[6] = 0x2001; //mov r0, #1
|
||||
off[1] = off[7] = 0; //nop
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchTwlShaHashChecks(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x10, 0xB5, 0x14, 0x22};
|
||||
|
||||
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[0] = 0x2001; //mov r0, #1
|
||||
off[1] = 0x4770;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 patchAgbBootSplash(u8 *pos, u32 size)
|
||||
{
|
||||
static const u8 pattern[] = {0x00, 0x00, 0x01, 0xEF};
|
||||
|
||||
u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||
|
||||
if(off == NULL) return 1;
|
||||
|
||||
off[2] = 0x26;
|
||||
|
||||
return 0;
|
||||
}
|
||||
67
arm9/source/patches.h
Normal file
67
arm9/source/patches.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Signature patches by an unknown author
|
||||
* Signature patches for old FIRMs by SciresM
|
||||
* firmlaunches patching code originally by delebile
|
||||
* FIRM partition writes patches by delebile
|
||||
* Idea for svcBreak patches from yellows8 and others on #3dsdev
|
||||
* TWL_FIRM patches by Steveice10 and others
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
u8 *getProcess9Info(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr);
|
||||
u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage);
|
||||
u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 *arm11ExceptionsPage, u8 **freeK11Space);
|
||||
u32 patchKernel11(u8 *pos, u32 size, u32 baseK11VA, u32 *arm11SvcTable, u32 *arm11ExceptionsPage);
|
||||
u32 patchSignatureChecks(u8 *pos, u32 size);
|
||||
u32 patchOldSignatureChecks(u8 *pos, u32 size);
|
||||
u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr);
|
||||
u32 patchFirmWrites(u8 *pos, u32 size);
|
||||
u32 patchOldFirmWrites(u8 *pos, u32 size);
|
||||
u32 patchTitleInstallMinVersionChecks(u8 *pos, u32 size, u32 firmVersion);
|
||||
u32 patchZeroKeyNcchEncryptionCheck(u8 *pos, u32 size);
|
||||
u32 patchNandNcchEncryptionCheck(u8 *pos, u32 size);
|
||||
u32 patchCheckForDevCommonKey(u8 *pos, u32 size);
|
||||
u32 patchK11ModuleLoading(u32 section0size, u32 modulesSize, u8 *startPos, u32 size);
|
||||
u32 patchArm9ExceptionHandlersInstall(u8 *pos, u32 size);
|
||||
u32 patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address);
|
||||
u32 patchKernel9Panic(u8 *pos, u32 size);
|
||||
u32 patchP9AccessChecks(u8 *pos, u32 size);
|
||||
u32 patchUnitInfoValueSet(u8 *pos, u32 size);
|
||||
u32 patchP9AMTicketWrapperZeroKeyIV(u8 *pos, u32 size, u32 firmVersion);
|
||||
u32 patchLgySignatureChecks(u8 *pos, u32 size);
|
||||
u32 patchTwlInvalidSignatureChecks(u8 *pos, u32 size);
|
||||
u32 patchTwlNintendoLogoChecks(u8 *pos, u32 size);
|
||||
u32 patchTwlWhitelistChecks(u8 *pos, u32 size);
|
||||
u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion);
|
||||
u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size);
|
||||
u32 patchTwlShaHashChecks(u8 *pos, u32 size);
|
||||
u32 patchAgbBootSplash(u8 *pos, u32 size);
|
||||
233
arm9/source/pin.c
Normal file
233
arm9/source/pin.c
Normal file
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code originally by reworks
|
||||
*/
|
||||
|
||||
#include "draw.h"
|
||||
#include "config.h"
|
||||
#include "screen.h"
|
||||
#include "utils.h"
|
||||
#include "memory.h"
|
||||
#include "buttons.h"
|
||||
#include "fs.h"
|
||||
#include "pin.h"
|
||||
#include "crypto.h"
|
||||
|
||||
static char pinKeyToLetter(u32 pressed)
|
||||
{
|
||||
static const char *keys = "AB--RLUD--XY";
|
||||
|
||||
u32 i;
|
||||
for(i = 31; pressed > 1; i--) pressed /= 2;
|
||||
|
||||
return keys[31 - i];
|
||||
}
|
||||
|
||||
void newPin(bool allowSkipping, u32 pinMode)
|
||||
{
|
||||
clearScreens(false);
|
||||
|
||||
u8 length = 4 + 2 * (pinMode - 1);
|
||||
|
||||
drawString(true, 10, 10, COLOR_TITLE, "Enter a new PIN using ABXY and the DPad");
|
||||
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, allowSkipping ? "Press START to skip, SELECT to reset" : "Press SELECT to reset");
|
||||
|
||||
drawFormattedString(true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE, "PIN (%u digits): ", length);
|
||||
|
||||
//Pad to AES block length with zeroes
|
||||
__attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0};
|
||||
|
||||
bool reset = false;
|
||||
u8 cnt = 0;
|
||||
|
||||
while(cnt < length)
|
||||
{
|
||||
if(reset)
|
||||
{
|
||||
for(u32 i = 0; i < cnt; i++)
|
||||
drawCharacter(true, 10 + (16 + 2 * i) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_BLACK, (char)enteredPassword[i]);
|
||||
|
||||
cnt = 0;
|
||||
reset = false;
|
||||
}
|
||||
|
||||
u32 pressed;
|
||||
do
|
||||
{
|
||||
pressed = waitInput(false);
|
||||
}
|
||||
while(!(pressed & PIN_BUTTONS));
|
||||
|
||||
pressed &= PIN_BUTTONS;
|
||||
if(!allowSkipping) pressed &= ~BUTTON_START;
|
||||
|
||||
if(pressed & BUTTON_START) return;
|
||||
|
||||
if(pressed & BUTTON_SELECT)
|
||||
{
|
||||
reset = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!pressed) continue;
|
||||
|
||||
//Add character to password
|
||||
enteredPassword[cnt] = (u8)pinKeyToLetter(pressed);
|
||||
|
||||
//Visualize character on screen
|
||||
drawCharacter(true, 10 + (16 + 2 * cnt) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE, enteredPassword[cnt]);
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
PinData pin;
|
||||
|
||||
memcpy(pin.magic, "PINF", 4);
|
||||
pin.formatVersionMajor = PIN_VERSIONMAJOR;
|
||||
pin.formatVersionMinor = PIN_VERSIONMINOR;
|
||||
|
||||
__attribute__((aligned(4))) u8 tmp[SHA_256_HASH_SIZE],
|
||||
lengthBlock[AES_BLOCK_SIZE] = {0};
|
||||
lengthBlock[0] = length;
|
||||
|
||||
computePinHash(tmp, lengthBlock);
|
||||
memcpy(pin.lengthHash, tmp, sizeof(tmp));
|
||||
|
||||
computePinHash(tmp, enteredPassword);
|
||||
memcpy(pin.hash, tmp, sizeof(tmp));
|
||||
|
||||
if(!fileWrite(&pin, PIN_FILE, sizeof(PinData)))
|
||||
error("Error writing the PIN file");
|
||||
}
|
||||
|
||||
bool verifyPin(u32 pinMode)
|
||||
{
|
||||
PinData pin;
|
||||
|
||||
if(fileRead(&pin, PIN_FILE, sizeof(PinData)) != sizeof(PinData) ||
|
||||
memcmp(pin.magic, "PINF", 4) != 0 ||
|
||||
pin.formatVersionMajor != PIN_VERSIONMAJOR ||
|
||||
pin.formatVersionMinor != PIN_VERSIONMINOR)
|
||||
return false;
|
||||
|
||||
__attribute__((aligned(4))) u8 tmp[SHA_256_HASH_SIZE],
|
||||
lengthBlock[AES_BLOCK_SIZE] = {0};
|
||||
lengthBlock[0] = 4 + 2 * (pinMode - 1);
|
||||
|
||||
computePinHash(tmp, lengthBlock);
|
||||
|
||||
//Test vector verification (check if SD card has been used on another console or PIN length changed)
|
||||
if(memcmp(pin.lengthHash, tmp, sizeof(tmp)) != 0) return false;
|
||||
|
||||
initScreens();
|
||||
|
||||
swapFramebuffers(true);
|
||||
|
||||
drawString(true, 10, 10, COLOR_TITLE, "Enter the PIN using ABXY and the DPad to proceed");
|
||||
drawString(true, 10, 10 + SPACING_Y, COLOR_TITLE, "Press START to shutdown, SELECT to clear");
|
||||
|
||||
drawFormattedString(true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE, "PIN (%u digits): ", lengthBlock[0]);
|
||||
|
||||
bool isBottomSplashValid = getFileSize("splashpin.bin") == SCREEN_BOTTOM_FBSIZE;
|
||||
if(isBottomSplashValid)
|
||||
{
|
||||
isBottomSplashValid = fileRead(fbs[0].bottom, "splashpin.bin", SCREEN_BOTTOM_FBSIZE) == SCREEN_BOTTOM_FBSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
static const char *messageFile = "pinmessage.txt";
|
||||
char message[801];
|
||||
|
||||
u32 messageSize = fileRead(message, messageFile, sizeof(message) - 1);
|
||||
|
||||
if(messageSize != 0)
|
||||
{
|
||||
message[messageSize] = 0;
|
||||
drawString(false, 10, 10, COLOR_WHITE, message);
|
||||
}
|
||||
}
|
||||
swapFramebuffers(false);
|
||||
|
||||
//Pad to AES block length with zeroes
|
||||
__attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0};
|
||||
|
||||
bool unlock = false,
|
||||
reset = false;
|
||||
u8 cnt = 0;
|
||||
|
||||
while(!unlock)
|
||||
{
|
||||
if(reset)
|
||||
{
|
||||
for(u32 i = 0; i < cnt; i++)
|
||||
drawCharacter(true, 10 + (16 + 2 * i) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_BLACK, '*');
|
||||
|
||||
cnt = 0;
|
||||
reset = false;
|
||||
}
|
||||
|
||||
u32 pressed;
|
||||
do
|
||||
{
|
||||
pressed = waitInput(false);
|
||||
}
|
||||
while(!(pressed & PIN_BUTTONS));
|
||||
|
||||
if(pressed & BUTTON_START) mcuPowerOff();
|
||||
|
||||
pressed &= PIN_BUTTONS;
|
||||
|
||||
if(pressed & BUTTON_SELECT)
|
||||
{
|
||||
reset = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!pressed) continue;
|
||||
|
||||
//Add character to password
|
||||
enteredPassword[cnt] = (u8)pinKeyToLetter(pressed);
|
||||
|
||||
//Visualize character on screen
|
||||
drawCharacter(true, 10 + (16 + 2 * cnt) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE, '*');
|
||||
|
||||
if(++cnt < lengthBlock[0]) continue;
|
||||
|
||||
computePinHash(tmp, enteredPassword);
|
||||
unlock = memcmp(pin.hash, tmp, sizeof(tmp)) == 0;
|
||||
|
||||
if(!unlock)
|
||||
{
|
||||
reset = true;
|
||||
|
||||
drawString(true, 10, 10 + 5 * SPACING_Y, COLOR_RED, "Wrong PIN, try again");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
40
arm9/source/pin.h
Normal file
40
arm9/source/pin.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code originally by reworks
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define PIN_FILE "pin.bin"
|
||||
#define PIN_VERSIONMAJOR 1
|
||||
#define PIN_VERSIONMINOR 3
|
||||
|
||||
void newPin(bool allowSkipping, u32 pinMode);
|
||||
bool verifyPin(u32 pinMode);
|
||||
120
arm9/source/screen.c
Normal file
120
arm9/source/screen.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others
|
||||
* Screen deinit code by tiniVi
|
||||
*/
|
||||
|
||||
#include "screen.h"
|
||||
#include "config.h"
|
||||
#include "memory.h"
|
||||
#include "i2c.h"
|
||||
#include "utils.h"
|
||||
|
||||
bool needToSetupScreens = true;
|
||||
|
||||
struct fb fbs[2] =
|
||||
{
|
||||
{
|
||||
.top_left = (u8 *)0x18300000,
|
||||
.top_right = (u8 *)0x18300000,
|
||||
.bottom = (u8 *)0x18346500,
|
||||
},
|
||||
{
|
||||
.top_left = (u8 *)0x18400000,
|
||||
.top_right = (u8 *)0x18400000,
|
||||
.bottom = (u8 *)0x18446500,
|
||||
},
|
||||
};
|
||||
|
||||
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
|
||||
|
||||
static volatile Arm11Operation *operation = (volatile Arm11Operation *)0x1FF80004;
|
||||
|
||||
static void invokeArm11Function(Arm11Operation op)
|
||||
{
|
||||
while(*operation != ARM11_READY);
|
||||
*operation = op;
|
||||
while(*operation != ARM11_READY);
|
||||
}
|
||||
|
||||
void prepareArm11ForFirmlaunch(void)
|
||||
{
|
||||
invokeArm11Function(PREPARE_ARM11_FOR_FIRMLAUNCH);
|
||||
}
|
||||
|
||||
void deinitScreens(void)
|
||||
{
|
||||
if(ARESCREENSINITIALIZED) invokeArm11Function(DEINIT_SCREENS);
|
||||
}
|
||||
|
||||
void updateBrightness(u32 brightnessIndex)
|
||||
{
|
||||
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[brightnessIndex];
|
||||
invokeArm11Function(UPDATE_BRIGHTNESS);
|
||||
}
|
||||
|
||||
void swapFramebuffers(bool isAlternate)
|
||||
{
|
||||
*(volatile bool *)ARM11_PARAMETERS_ADDRESS = isAlternate;
|
||||
invokeArm11Function(SWAP_FRAMEBUFFERS);
|
||||
}
|
||||
|
||||
void clearScreens(bool isAlternate)
|
||||
{
|
||||
struct fb *fbTemp = isAlternate ? &fbs[1] : &fbs[0];
|
||||
|
||||
*(volatile struct fb *)ARM11_PARAMETERS_ADDRESS = *fbTemp;
|
||||
invokeArm11Function(CLEAR_SCREENS);
|
||||
}
|
||||
|
||||
void initScreens(void)
|
||||
{
|
||||
if(needToSetupScreens)
|
||||
{
|
||||
if(!ARESCREENSINITIALIZED || bootType == FIRMLAUNCH)
|
||||
{
|
||||
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)];
|
||||
memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs));
|
||||
invokeArm11Function(INIT_SCREENS);
|
||||
|
||||
//Turn on backlight
|
||||
I2C_writeReg(I2C_DEV_MCU, 0x22, 0x2A);
|
||||
wait(5);
|
||||
}
|
||||
else updateBrightness(MULTICONFIG(BRIGHTNESS));
|
||||
|
||||
memcpy((void *)ARM11_PARAMETERS_ADDRESS, fbs, sizeof(fbs));
|
||||
invokeArm11Function(SETUP_FRAMEBUFFERS);
|
||||
|
||||
clearScreens(true);
|
||||
needToSetupScreens = false;
|
||||
}
|
||||
|
||||
clearScreens(false);
|
||||
swapFramebuffers(false);
|
||||
}
|
||||
75
arm9/source/screen.h
Normal file
75
arm9/source/screen.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others
|
||||
* Screen deinit code by tiniVi
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define PDN_GPU_CNT (*(vu32 *)0x10141200)
|
||||
|
||||
#define ARESCREENSINITIALIZED ((PDN_GPU_CNT & 0xFF) != 1)
|
||||
|
||||
#define ARM11_PARAMETERS_ADDRESS 0x1FFFF000
|
||||
|
||||
#define SCREEN_TOP_WIDTH 400
|
||||
#define SCREEN_BOTTOM_WIDTH 320
|
||||
#define SCREEN_HEIGHT 240
|
||||
#define SCREEN_TOP_FBSIZE (3 * SCREEN_TOP_WIDTH * SCREEN_HEIGHT)
|
||||
#define SCREEN_BOTTOM_FBSIZE (3 * SCREEN_BOTTOM_WIDTH * SCREEN_HEIGHT)
|
||||
|
||||
struct fb {
|
||||
u8 *top_left;
|
||||
u8 *top_right;
|
||||
u8 *bottom;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INIT_SCREENS = 0,
|
||||
SETUP_FRAMEBUFFERS,
|
||||
CLEAR_SCREENS,
|
||||
SWAP_FRAMEBUFFERS,
|
||||
UPDATE_BRIGHTNESS,
|
||||
DEINIT_SCREENS,
|
||||
PREPARE_ARM11_FOR_FIRMLAUNCH,
|
||||
ARM11_READY,
|
||||
} Arm11Operation;
|
||||
|
||||
extern struct fb fbs[2];
|
||||
|
||||
extern bool needToSetupScreens;
|
||||
|
||||
void prepareArm11ForFirmlaunch(void);
|
||||
void deinitScreens(void);
|
||||
void swapFramebuffers(bool isAlternate);
|
||||
void updateBrightness(u32 brightnessIndex);
|
||||
void clearScreens(bool isAlternate);
|
||||
void initScreens(void);
|
||||
166
arm9/source/start.s
Normal file
166
arm9/source/start.s
Normal file
@@ -0,0 +1,166 @@
|
||||
@ This file is part of Luma3DS
|
||||
@ Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
@
|
||||
@ 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 <http://www.gnu.org/licenses/>.
|
||||
@
|
||||
@ Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
@ * Requiring preservation of specified reasonable legal notices or
|
||||
@ author attributions in that material or in the Appropriate Legal
|
||||
@ Notices displayed by works containing it.
|
||||
@ * Prohibiting misrepresentation of the origin of that material,
|
||||
@ or requiring that modified versions of such material be marked in
|
||||
@ reasonable ways as different from the original version.
|
||||
|
||||
.section .text.start, "ax", %progbits
|
||||
.align 4
|
||||
.global _start
|
||||
_start:
|
||||
@ Disable interrupts and switch to supervisor mode (also clear flags)
|
||||
msr cpsr_cxsf, #0xD3
|
||||
|
||||
@ Check if r0-r2 are 0 (r0-sp are supposed to be 0), and for regions 0, 5 and 7 of the MPU config
|
||||
@ This is not foolproof but should work well enough
|
||||
cmp r0, #0
|
||||
cmpeq r1, #0
|
||||
cmpeq r2, #0
|
||||
ldreq r4, =0x20000035
|
||||
mrceq p15, 0, r5, c6, c0, 0
|
||||
cmpeq r4, r5
|
||||
mrceq p15, 0, r5, c6, c5, 0
|
||||
ldreq r4, =0x07FF801D
|
||||
cmpeq r4, r5
|
||||
mrceq p15, 0, r5, c6, c7, 0
|
||||
ldreq r4, =0x1FFFE019
|
||||
cmpeq r4, r5
|
||||
ldreq r2, =0xB002
|
||||
|
||||
mov r9, r0
|
||||
mov r10, r1
|
||||
mov r11, r2
|
||||
|
||||
@ Change the stack pointer
|
||||
mov sp, #0x08100000
|
||||
|
||||
@ Disable caches / MPU
|
||||
mrc p15, 0, r4, c1, c0, 0 @ read control register
|
||||
bic r4, #(1<<16) @ - DTCM disable
|
||||
bic r4, #(1<<12) @ - instruction cache disable
|
||||
bic r4, #(1<<2) @ - data cache disable
|
||||
bic r4, #(1<<0) @ - MPU disable
|
||||
mcr p15, 0, r4, c1, c0, 0 @ write control register
|
||||
|
||||
@ Invalidate both caches, discarding any data they may contain,
|
||||
@ then drain the write buffer
|
||||
mov r4, #0
|
||||
mcr p15, 0, r4, c7, c5, 0
|
||||
mcr p15, 0, r4, c7, c6, 0
|
||||
mcr p15, 0, r4, c7, c10, 4
|
||||
|
||||
@ Give read/write access to all the memory regions
|
||||
ldr r0, =0x33333333
|
||||
mcr p15, 0, r0, c5, c0, 2 @ write data access
|
||||
mcr p15, 0, r0, c5, c0, 3 @ write instruction access
|
||||
|
||||
@ Set MPU permissions and cache settings
|
||||
ldr r0, =0xFFFF001D @ ffff0000 32k | bootrom (unprotected part)
|
||||
ldr r1, =0xFFF0001B @ fff00000 16k | dtcm
|
||||
ldr r2, =0x01FF801D @ 01ff8000 32k | itcm
|
||||
ldr r3, =0x08000027 @ 08000000 1M | arm9 mem
|
||||
ldr r4, =0x10000029 @ 10000000 2M | io mem (Arm9 / first 2MB)
|
||||
ldr r5, =0x20000035 @ 20000000 128M | fcram
|
||||
ldr r6, =0x1FF00027 @ 1FF00000 1M | dsp / axi wram
|
||||
ldr r7, =0x1800002D @ 18000000 8M | vram (+ 2MB)
|
||||
mov r8, #0x29
|
||||
mcr p15, 0, r0, c6, c0, 0
|
||||
mcr p15, 0, r1, c6, c1, 0
|
||||
mcr p15, 0, r2, c6, c2, 0
|
||||
mcr p15, 0, r3, c6, c3, 0
|
||||
mcr p15, 0, r4, c6, c4, 0
|
||||
mcr p15, 0, r5, c6, c5, 0
|
||||
mcr p15, 0, r6, c6, c6, 0
|
||||
mcr p15, 0, r7, c6, c7, 0
|
||||
mcr p15, 0, r8, c3, c0, 0 @ Write bufferable 0, 3, 5
|
||||
mcr p15, 0, r8, c2, c0, 0 @ Data cacheable 0, 3, 5
|
||||
mcr p15, 0, r8, c2, c0, 1 @ Inst cacheable 0, 3, 5
|
||||
|
||||
@ Set DTCM address and size to the default values
|
||||
ldr r1, =0xFFF0000A @ set DTCM address and size
|
||||
mcr p15, 0, r1, c9, c1, 0 @ set the dtcm Region Register
|
||||
|
||||
@ Enable caches / MPU / ITCM
|
||||
mrc p15, 0, r0, c1, c0, 0 @ read control register
|
||||
orr r0, r0, #(1<<18) @ - ITCM enable
|
||||
orr r0, r0, #(1<<16) @ - DTCM enable
|
||||
orr r0, r0, #(1<<13) @ - alternate exception vectors enable
|
||||
orr r0, r0, #(1<<12) @ - instruction cache enable
|
||||
orr r0, r0, #(1<<2) @ - data cache enable
|
||||
orr r0, r0, #(1<<0) @ - MPU enable
|
||||
mcr p15, 0, r0, c1, c0, 0 @ write control register
|
||||
|
||||
@ Clear BSS
|
||||
ldr r0, =__bss_start__
|
||||
mov r1, #0
|
||||
ldr r2, =__bss_end__
|
||||
sub r2, r0
|
||||
bl memset
|
||||
|
||||
bl __libc_init_array
|
||||
|
||||
mov r0, r9
|
||||
mov r1, r10
|
||||
mov r2, r11
|
||||
b main
|
||||
.pool
|
||||
|
||||
.section .chainloader.text.start, "ax", %progbits
|
||||
.align 4
|
||||
.global chainload
|
||||
.type chainload, %function
|
||||
chainload:
|
||||
ldr sp, =__itcm_stack_top__
|
||||
b chainloader_main
|
||||
.pool
|
||||
|
||||
.global disableMpuAndJumpToEntrypoints
|
||||
.type disableMpuAndJumpToEntrypoints, %function
|
||||
disableMpuAndJumpToEntrypoints:
|
||||
mov r4, r0
|
||||
mov r5, r1
|
||||
mov r6, r2
|
||||
mov r7, r3
|
||||
|
||||
@ Flush caches
|
||||
ldr r12, =0xFFFF0830
|
||||
blx r12
|
||||
ldr r12, =0xFFFF0AB4
|
||||
blx r12
|
||||
|
||||
@ Disable caches / MPU
|
||||
mrc p15, 0, r0, c1, c0, 0 @ read control register
|
||||
bic r0, #(1<<12) @ - instruction cache disable
|
||||
bic r0, #(1<<2) @ - data cache disable
|
||||
bic r0, #(1<<0) @ - MPU disable
|
||||
mcr p15, 0, r0, c1, c0, 0 @ write control register
|
||||
|
||||
@ Set the Arm11 entrypoint
|
||||
mov r0, #0x20000000
|
||||
str r7, [r0, #-4]
|
||||
|
||||
@ Jump to the Arm9 entrypoint
|
||||
mov r0, r4
|
||||
mov r1, r5
|
||||
ldr r2, =0x3BEEF
|
||||
bx r6
|
||||
|
||||
.pool
|
||||
49
arm9/source/strings.c
Normal file
49
arm9/source/strings.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "strings.h"
|
||||
|
||||
u32 hexAtoi(const char *in, u32 digits)
|
||||
{
|
||||
u32 res = 0;
|
||||
char *tmp = (char *)in;
|
||||
|
||||
for(u32 i = 0; i < digits && *tmp != 0; tmp++, i++)
|
||||
res = (*tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0') + (res << 4);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
u32 decAtoi(const char *in, u32 digits)
|
||||
{
|
||||
u32 res = 0;
|
||||
char *tmp = (char *)in;
|
||||
|
||||
for(u32 i = 0; i < digits && *tmp != 0; tmp++, i++)
|
||||
res = *tmp - '0' + res * 10;
|
||||
|
||||
return res;
|
||||
}
|
||||
32
arm9/source/strings.h
Normal file
32
arm9/source/strings.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
u32 hexAtoi(const char *in, u32 digits);
|
||||
u32 decAtoi(const char *in, u32 digits);
|
||||
132
arm9/source/types.h
Normal file
132
arm9/source/types.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
//Common data types
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
typedef volatile u8 vu8;
|
||||
typedef volatile u16 vu16;
|
||||
typedef volatile u32 vu32;
|
||||
typedef volatile u64 vu64;
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
typedef volatile s8 vs8;
|
||||
typedef volatile s16 vs16;
|
||||
typedef volatile s32 vs32;
|
||||
typedef volatile s64 vs64;
|
||||
|
||||
#include "3dsheaders.h"
|
||||
|
||||
#define CFG_BOOTENV (*(vu32 *)0x10010000)
|
||||
#define CFG_UNITINFO (*(vu8 *)0x10010010)
|
||||
#define CFG_TWLUNITINFO (*(vu8 *)0x10010014)
|
||||
#define OTP_DEVCONSOLEID (*(vu64 *)0x10012000)
|
||||
#define OTP_TWLCONSOLEID (*(vu64 *)0x10012100)
|
||||
#define CFG11_SOCINFO (*(vu32 *)0x10140FFC)
|
||||
|
||||
#define ISN3DS (CFG11_SOCINFO & 2)
|
||||
#define ISDEVUNIT (CFG_UNITINFO != 0)
|
||||
|
||||
typedef struct __attribute__((packed, aligned(4)))
|
||||
{
|
||||
char magic[4];
|
||||
u16 formatVersionMajor, formatVersionMinor;
|
||||
|
||||
u32 config, multiConfig, bootConfig;
|
||||
u64 hbldr3dsxTitleId;
|
||||
u32 rosalinaMenuCombo;
|
||||
} CfgData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char magic[4];
|
||||
u16 formatVersionMajor, formatVersionMinor;
|
||||
|
||||
u8 lengthHash[32];
|
||||
u8 hash[32];
|
||||
} PinData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 magic[2];
|
||||
u16 versionMinor, versionMajor;
|
||||
|
||||
u16 processor, core;
|
||||
u32 type;
|
||||
|
||||
u32 totalSize;
|
||||
u32 registerDumpSize;
|
||||
u32 codeDumpSize;
|
||||
u32 stackDumpSize;
|
||||
u32 additionalDataSize;
|
||||
} ExceptionDumpHeader;
|
||||
|
||||
typedef enum FirmwareSource
|
||||
{
|
||||
FIRMWARE_SYSNAND = 0,
|
||||
FIRMWARE_EMUNAND,
|
||||
FIRMWARE_EMUNAND2,
|
||||
FIRMWARE_EMUNAND3,
|
||||
FIRMWARE_EMUNAND4
|
||||
} FirmwareSource;
|
||||
|
||||
typedef enum FirmwareType
|
||||
{
|
||||
NATIVE_FIRM = 0,
|
||||
TWL_FIRM,
|
||||
AGB_FIRM,
|
||||
SAFE_FIRM,
|
||||
SYSUPDATER_FIRM,
|
||||
NATIVE_FIRM1X2X
|
||||
} FirmwareType;
|
||||
|
||||
typedef enum bootType
|
||||
{
|
||||
B9S = 0,
|
||||
B9SNTR,
|
||||
FIRM0,
|
||||
FIRM1,
|
||||
FIRMLAUNCH,
|
||||
NTR
|
||||
} BootType;
|
||||
|
||||
extern bool isSdMode;
|
||||
|
||||
extern BootType bootType;
|
||||
|
||||
extern u16 launchedFirmTidLow[8];
|
||||
extern u16 launchedPath[80+1];
|
||||
156
arm9/source/utils.c
Normal file
156
arm9/source/utils.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* waitInput function based on code by d0k3 https://github.com/d0k3/Decrypt9WIP/blob/master/source/hid.c
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
#include "i2c.h"
|
||||
#include "buttons.h"
|
||||
#include "screen.h"
|
||||
#include "draw.h"
|
||||
#include "cache.h"
|
||||
#include "fmt.h"
|
||||
#include "memory.h"
|
||||
#include "fs.h"
|
||||
|
||||
static void startChrono(void)
|
||||
{
|
||||
static bool isChronoStarted = false;
|
||||
|
||||
if(isChronoStarted) return;
|
||||
|
||||
REG_TIMER_CNT(0) = 0; //67MHz
|
||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 4; //Count-up
|
||||
|
||||
for(u32 i = 0; i < 4; i++) REG_TIMER_VAL(i) = 0;
|
||||
|
||||
REG_TIMER_CNT(0) = 0x80; //67MHz; enabled
|
||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
|
||||
|
||||
isChronoStarted = true;
|
||||
}
|
||||
|
||||
static u64 chrono(void)
|
||||
{
|
||||
u64 res = 0;
|
||||
for(u32 i = 0; i < 4; i++) res |= REG_TIMER_VAL(i) << (16 * i);
|
||||
|
||||
res /= (TICKS_PER_SEC / 1000);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
u32 waitInput(bool isMenu)
|
||||
{
|
||||
static u64 dPadDelay = 0ULL;
|
||||
u64 initialValue = 0ULL;
|
||||
u32 key,
|
||||
oldKey = HID_PAD;
|
||||
bool shouldShellShutdown = bootType != B9SNTR && bootType != NTR;
|
||||
|
||||
if(isMenu)
|
||||
{
|
||||
dPadDelay = dPadDelay > 0ULL ? 87ULL : 143ULL;
|
||||
startChrono();
|
||||
initialValue = chrono();
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
key = HID_PAD;
|
||||
|
||||
if(!key)
|
||||
{
|
||||
if(shouldShellShutdown)
|
||||
{
|
||||
u8 shellState = I2C_readReg(I2C_DEV_MCU, 0xF);
|
||||
wait(5);
|
||||
if(!(shellState & 2)) mcuPowerOff();
|
||||
}
|
||||
|
||||
u8 intStatus = I2C_readReg(I2C_DEV_MCU, 0x10);
|
||||
wait(5);
|
||||
if(intStatus & 1) mcuPowerOff(); //Power button pressed
|
||||
|
||||
oldKey = 0;
|
||||
dPadDelay = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key == oldKey && (!isMenu || (!(key & DPAD_BUTTONS) || chrono() - initialValue < dPadDelay))) continue;
|
||||
|
||||
//Make sure the key is pressed
|
||||
u32 i;
|
||||
for(i = 0; i < 0x13000 && key == HID_PAD; i++);
|
||||
if(i == 0x13000) break;
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void mcuPowerOff(void)
|
||||
{
|
||||
if(!needToSetupScreens) clearScreens(false);
|
||||
|
||||
//Shutdown LCD
|
||||
if(ARESCREENSINITIALIZED) I2C_writeReg(I2C_DEV_MCU, 0x22, 1 << 0);
|
||||
|
||||
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
||||
flushEntireDCache();
|
||||
|
||||
I2C_writeReg(I2C_DEV_MCU, 0x20, 1 << 0);
|
||||
while(true);
|
||||
}
|
||||
|
||||
void wait(u64 amount)
|
||||
{
|
||||
startChrono();
|
||||
|
||||
u64 initialValue = chrono();
|
||||
|
||||
while(chrono() - initialValue < amount);
|
||||
}
|
||||
|
||||
void error(const char *fmt, ...)
|
||||
{
|
||||
char buf[DRAW_MAX_FORMATTED_STRING_SIZE + 1];
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
initScreens();
|
||||
drawString(true, 10, 10, COLOR_RED, "An error has occurred:");
|
||||
u32 posY = drawString(true, 10, 30, COLOR_WHITE, buf);
|
||||
drawString(true, 10, posY + 2 * SPACING_Y, COLOR_WHITE, "Press any button to shutdown");
|
||||
|
||||
waitInput(false);
|
||||
|
||||
mcuPowerOff();
|
||||
}
|
||||
45
arm9/source/utils.h
Normal file
45
arm9/source/utils.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
/*
|
||||
* waitInput function based on code by d0k3 https://github.com/d0k3/Decrypt9WIP/blob/master/source/hid.c
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define TICKS_PER_SEC 67027964ULL
|
||||
#define REG_TIMER_CNT(i) *(vu16 *)(0x10003002 + 4 * i)
|
||||
#define REG_TIMER_VAL(i) *(vu16 *)(0x10003000 + 4 * i)
|
||||
|
||||
#define MAKE_BRANCH(src,dst) (0xEA000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
#define MAKE_BRANCH_LINK(src,dst) (0xEB000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
|
||||
u32 waitInput(bool isMenu);
|
||||
void mcuPowerOff(void);
|
||||
void wait(u64 amount);
|
||||
void error(const char *fmt, ...);
|
||||
@@ -1,97 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 reserved[5];
|
||||
u8 flag;
|
||||
u8 remasterversion[2];
|
||||
} PACKED exheader_systeminfoflags;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 address;
|
||||
u32 nummaxpages;
|
||||
u32 codesize;
|
||||
} PACKED exheader_codesegmentinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 name[8];
|
||||
exheader_systeminfoflags flags;
|
||||
exheader_codesegmentinfo text;
|
||||
u8 stacksize[4];
|
||||
exheader_codesegmentinfo ro;
|
||||
u8 reserved[4];
|
||||
exheader_codesegmentinfo data;
|
||||
u32 bsssize;
|
||||
} PACKED exheader_codesetinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 programid[0x30];
|
||||
} PACKED exheader_dependencylist;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 savedatasize[4];
|
||||
u8 reserved[4];
|
||||
u8 jumpid[8];
|
||||
u8 reserved2[0x30];
|
||||
} PACKED exheader_systeminfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 extsavedataid[8];
|
||||
u8 systemsavedataid[8];
|
||||
u8 reserved[8];
|
||||
u8 accessinfo[7];
|
||||
u8 otherattributes;
|
||||
} PACKED exheader_storageinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u64 programid;
|
||||
u8 flags[8];
|
||||
u16 resourcelimitdescriptor[0x10];
|
||||
exheader_storageinfo storageinfo;
|
||||
u64 serviceaccesscontrol[0x20];
|
||||
u8 reserved[0x1f];
|
||||
u8 resourcelimitcategory;
|
||||
} PACKED exheader_arm11systemlocalcaps;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 descriptors[28];
|
||||
u8 reserved[0x10];
|
||||
} PACKED exheader_arm11kernelcapabilities;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 descriptors[15];
|
||||
u8 descversion;
|
||||
} PACKED exheader_arm9accesscontrol;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// systemcontrol info {
|
||||
// coreinfo {
|
||||
exheader_codesetinfo codesetinfo;
|
||||
exheader_dependencylist deplist;
|
||||
// }
|
||||
exheader_systeminfo systeminfo;
|
||||
// }
|
||||
// accesscontrolinfo {
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
// }
|
||||
struct {
|
||||
u8 signature[0x100];
|
||||
u8 ncchpubkeymodulus[0x100];
|
||||
exheader_arm11systemlocalcaps arm11systemlocalcaps;
|
||||
exheader_arm11kernelcapabilities arm11kernelcaps;
|
||||
exheader_arm9accesscontrol arm9accesscontrol;
|
||||
} PACKED accessdesc;
|
||||
} PACKED exheader_header;
|
||||
@@ -1,109 +0,0 @@
|
||||
#include <3ds.h>
|
||||
#include "fsldr.h"
|
||||
#include "fsreg.h"
|
||||
#include "srvsys.h"
|
||||
|
||||
#define SDK_VERSION 0x70200C8
|
||||
|
||||
static Handle fsldrHandle;
|
||||
static int fsldrRefCount;
|
||||
|
||||
// MAKE SURE fsreg has been init before calling this
|
||||
static Result fsldrPatchPermissions(void)
|
||||
{
|
||||
u32 pid;
|
||||
Result res;
|
||||
FS_ProgramInfo info;
|
||||
u32 storage[8] = {0};
|
||||
|
||||
storage[6] = 0x680; // SDMC access and NAND access flag
|
||||
info.programId = 0x0004013000001302LL; // loader PID
|
||||
info.mediaType = MEDIATYPE_NAND;
|
||||
res = svcGetProcessId(&pid, 0xFFFF8001);
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, (u8 *)storage);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Result fsldrInit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if (AtomicPostIncrement(&fsldrRefCount)) return 0;
|
||||
|
||||
ret = srvSysGetServiceHandle(&fsldrHandle, "fs:LDR");
|
||||
if (R_SUCCEEDED(ret))
|
||||
{
|
||||
fsldrPatchPermissions();
|
||||
ret = FSLDR_InitializeWithSdkVersion(fsldrHandle, SDK_VERSION);
|
||||
ret = FSLDR_SetPriority(0);
|
||||
if (R_FAILED(ret)) svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
else
|
||||
{
|
||||
AtomicDecrement(&fsldrRefCount);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fsldrExit(void)
|
||||
{
|
||||
if (AtomicDecrement(&fsldrRefCount)) return;
|
||||
svcCloseHandle(fsldrHandle);
|
||||
}
|
||||
|
||||
Result FSLDR_InitializeWithSdkVersion(Handle session, u32 version)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x861,1,2); // 0x8610042
|
||||
cmdbuf[1] = version;
|
||||
cmdbuf[2] = 32;
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(session))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSLDR_SetPriority(u32 priority)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x862,1,0); // 0x8620040
|
||||
cmdbuf[1] = priority;
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsldrHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSLDR_OpenFileDirectly(Handle* out, FS_Archive archive, FS_Path path, u32 openFlags, u32 attributes)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x803,8,4); // 0x8030204
|
||||
cmdbuf[1] = 0;
|
||||
cmdbuf[2] = archive.id;
|
||||
cmdbuf[3] = archive.lowPath.type;
|
||||
cmdbuf[4] = archive.lowPath.size;
|
||||
cmdbuf[5] = path.type;
|
||||
cmdbuf[6] = path.size;
|
||||
cmdbuf[7] = openFlags;
|
||||
cmdbuf[8] = attributes;
|
||||
cmdbuf[9] = IPC_Desc_StaticBuffer(archive.lowPath.size, 2);
|
||||
cmdbuf[10] = (u32) archive.lowPath.data;
|
||||
cmdbuf[11] = IPC_Desc_StaticBuffer(path.size, 0);
|
||||
cmdbuf[12] = (u32) path.data;
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsldrHandle))) return ret;
|
||||
|
||||
if(out) *out = cmdbuf[3];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
Result fsldrInit(void);
|
||||
void fsldrExit(void);
|
||||
Result FSLDR_InitializeWithSdkVersion(Handle session, u32 version);
|
||||
Result FSLDR_SetPriority(u32 priority);
|
||||
Result FSLDR_OpenFileDirectly(Handle* out, FS_Archive archive, FS_Path path, u32 openFlags, u32 attributes);
|
||||
@@ -1,116 +0,0 @@
|
||||
#include <3ds.h>
|
||||
#include <string.h>
|
||||
#include "fsreg.h"
|
||||
#include "srvsys.h"
|
||||
|
||||
static Handle fsregHandle;
|
||||
static int fsregRefCount;
|
||||
|
||||
Result fsregInit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if (AtomicPostIncrement(&fsregRefCount)) return 0;
|
||||
|
||||
ret = srvSysGetServiceHandle(&fsregHandle, "fs:REG");
|
||||
|
||||
if (R_FAILED(ret)) AtomicDecrement(&fsregRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fsregExit(void)
|
||||
{
|
||||
if (AtomicDecrement(&fsregRefCount)) return;
|
||||
svcCloseHandle(fsregHandle);
|
||||
}
|
||||
|
||||
Result FSREG_CheckHostLoadId(u64 prog_handle)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x406,2,0); // 0x4060080
|
||||
cmdbuf[1] = (u32) (prog_handle);
|
||||
cmdbuf[2] = (u32) (prog_handle >> 32);
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsregHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSREG_LoadProgram(u64 *prog_handle, FS_ProgramInfo *title)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x404,4,0); // 0x4040100
|
||||
memcpy(&cmdbuf[1], &title->programId, sizeof(u64));
|
||||
*(u8 *)&cmdbuf[3] = title->mediaType;
|
||||
memcpy(((u8 *)&cmdbuf[3])+1, &title->padding, 7);
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsregHandle))) return ret;
|
||||
*prog_handle = *(u64 *)&cmdbuf[2];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSREG_GetProgramInfo(exheader_header *exheader, u32 entry_count, u64 prog_handle)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x403,3,0); // 0x40300C0
|
||||
cmdbuf[1] = entry_count;
|
||||
*(u64 *)&cmdbuf[2] = prog_handle;
|
||||
cmdbuf[64] = ((entry_count << 10) << 14) | 2;
|
||||
cmdbuf[65] = (u32) exheader;
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsregHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSREG_UnloadProgram(u64 prog_handle)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x405,2,0); // 0x4050080
|
||||
cmdbuf[1] = (u32) (prog_handle);
|
||||
cmdbuf[2] = (u32) (prog_handle >> 32);
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsregHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSREG_Unregister(u32 pid)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x402,1,0); // 0x4020040
|
||||
cmdbuf[1] = pid;
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsregHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result FSREG_Register(u32 pid, u64 prog_handle, FS_ProgramInfo *info, void *storageinfo)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x401,0xf,0); // 0x40103C0
|
||||
cmdbuf[1] = pid;
|
||||
*(u64 *)&cmdbuf[2] = prog_handle;
|
||||
memcpy(&cmdbuf[4], &info->programId, sizeof(u64));
|
||||
*(u8 *)&cmdbuf[6] = info->mediaType;
|
||||
memcpy(((u8 *)&cmdbuf[6])+1, &info->padding, 7);
|
||||
memcpy((u8 *)&cmdbuf[8], storageinfo, 32);
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(fsregHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "exheader.h"
|
||||
|
||||
Result fsregInit(void);
|
||||
void fsregExit(void);
|
||||
Result FSREG_CheckHostLoadId(u64 prog_handle);
|
||||
Result FSREG_LoadProgram(u64 *prog_handle, FS_ProgramInfo *title);
|
||||
Result FSREG_GetProgramInfo(exheader_header *exheader, u32 entry_count, u64 prog_handle);
|
||||
Result FSREG_UnloadProgram(u64 prog_handle);
|
||||
Result FSREG_Unregister(u32 pid);
|
||||
Result FSREG_Register(u32 pid, u64 prog_handle, FS_ProgramInfo *info, void *storageinfo);
|
||||
@@ -1,593 +0,0 @@
|
||||
#include <3ds.h>
|
||||
#include <string.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include "patcher.h"
|
||||
#include "exheader.h"
|
||||
#include "ifile.h"
|
||||
#include "fsldr.h"
|
||||
#include "fsreg.h"
|
||||
#include "pxipm.h"
|
||||
#include "srvsys.h"
|
||||
|
||||
#define MAX_SESSIONS 1
|
||||
|
||||
const char CODE_PATH[] = {0x01, 0x00, 0x00, 0x00, 0x2E, 0x63, 0x6F, 0x64, 0x65, 0x00, 0x00, 0x00};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 text_addr;
|
||||
u32 text_size;
|
||||
u32 ro_addr;
|
||||
u32 ro_size;
|
||||
u32 data_addr;
|
||||
u32 data_size;
|
||||
u32 total_size;
|
||||
} prog_addrs_t;
|
||||
|
||||
static Handle g_handles[MAX_SESSIONS+2];
|
||||
static int g_active_handles;
|
||||
static u64 g_cached_prog_handle;
|
||||
static exheader_header g_exheader;
|
||||
static char g_ret_buf[1024];
|
||||
|
||||
static int lzss_decompress(u8 *end)
|
||||
{
|
||||
unsigned int v1; // r1@2
|
||||
u8 *v2; // r2@2
|
||||
u8 *v3; // r3@2
|
||||
u8 *v4; // r1@2
|
||||
char v5; // r5@4
|
||||
char v6; // t1@4
|
||||
signed int v7; // r6@4
|
||||
int v9; // t1@7
|
||||
u8 *v11; // r3@8
|
||||
int v12; // r12@8
|
||||
int v13; // t1@8
|
||||
int v14; // t1@8
|
||||
unsigned int v15; // r7@8
|
||||
int v16; // r12@8
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if ( end )
|
||||
{
|
||||
v1 = *((u32 *)end - 2);
|
||||
v2 = &end[*((u32 *)end - 1)];
|
||||
v3 = &end[-(v1 >> 24)];
|
||||
v4 = &end[-(v1 & 0xFFFFFF)];
|
||||
while ( v3 > v4 )
|
||||
{
|
||||
v6 = *(v3-- - 1);
|
||||
v5 = v6;
|
||||
v7 = 8;
|
||||
while ( 1 )
|
||||
{
|
||||
if ( (v7-- < 1) )
|
||||
break;
|
||||
if ( v5 & 0x80 )
|
||||
{
|
||||
v13 = *(v3 - 1);
|
||||
v11 = v3 - 1;
|
||||
v12 = v13;
|
||||
v14 = *(v11 - 1);
|
||||
v3 = v11 - 1;
|
||||
v15 = ((v14 | (v12 << 8)) & 0xFFFF0FFF) + 2;
|
||||
v16 = v12 + 32;
|
||||
do
|
||||
{
|
||||
ret = v2[v15];
|
||||
*(v2-- - 1) = ret;
|
||||
v16 -= 16;
|
||||
}
|
||||
while ( !(v16 < 0) );
|
||||
}
|
||||
else
|
||||
{
|
||||
v9 = *(v3-- - 1);
|
||||
ret = v9;
|
||||
*(v2-- - 1) = v9;
|
||||
}
|
||||
v5 *= 2;
|
||||
if ( v3 <= v4 )
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Result allocate_shared_mem(prog_addrs_t *shared, prog_addrs_t *vaddr, int flags)
|
||||
{
|
||||
u32 dummy;
|
||||
|
||||
memcpy(shared, vaddr, sizeof(prog_addrs_t));
|
||||
shared->text_addr = 0x10000000;
|
||||
shared->ro_addr = shared->text_addr + (shared->text_size << 12);
|
||||
shared->data_addr = shared->ro_addr + (shared->ro_size << 12);
|
||||
return svcControlMemory(&dummy, shared->text_addr, 0, shared->total_size << 12, (flags & 0xF00) | MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
|
||||
}
|
||||
|
||||
static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int is_compressed)
|
||||
{
|
||||
IFile file;
|
||||
FS_Archive archive;
|
||||
FS_Path path;
|
||||
Result res;
|
||||
u64 size;
|
||||
u64 total;
|
||||
|
||||
archive.id = ARCHIVE_SAVEDATA_AND_CONTENT2;
|
||||
archive.lowPath.type = PATH_BINARY;
|
||||
archive.lowPath.data = &prog_handle;
|
||||
archive.lowPath.size = 8;
|
||||
//archive.handle = prog_handle; // not needed
|
||||
path.type = PATH_BINARY;
|
||||
path.data = CODE_PATH;
|
||||
path.size = sizeof(CODE_PATH);
|
||||
if (R_FAILED(IFile_Open(&file, archive, path, FS_OPEN_READ)))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
|
||||
// get file size
|
||||
if (R_FAILED(IFile_GetSize(&file, &size)))
|
||||
{
|
||||
IFile_Close(&file);
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
|
||||
// check size
|
||||
if (size > (u64)shared->total_size << 12)
|
||||
{
|
||||
IFile_Close(&file);
|
||||
return 0xC900464F;
|
||||
}
|
||||
|
||||
// read code
|
||||
res = IFile_Read(&file, &total, (void *)shared->text_addr, size);
|
||||
IFile_Close(&file); // done reading
|
||||
if (R_FAILED(res))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
|
||||
// decompress
|
||||
if (is_compressed)
|
||||
{
|
||||
lzss_decompress((u8 *)shared->text_addr + size);
|
||||
}
|
||||
|
||||
// patch
|
||||
patchCode(progid, (u8 *)shared->text_addr, shared->total_size << 12);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Result loader_GetProgramInfo(exheader_header *exheader, u64 prog_handle)
|
||||
{
|
||||
Result res;
|
||||
|
||||
if (prog_handle >> 32 == 0xFFFF0000)
|
||||
{
|
||||
return FSREG_GetProgramInfo(exheader, 1, prog_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = FSREG_CheckHostLoadId(prog_handle);
|
||||
//if ((res >= 0 && (unsigned)res >> 27) || (res < 0 && ((unsigned)res >> 27)-32))
|
||||
//so use PXIPM if FSREG fails OR returns "info", is the second condition a bug?
|
||||
if (R_FAILED(res) || (R_SUCCEEDED(res) && R_LEVEL(res) != RL_SUCCESS))
|
||||
{
|
||||
return PXIPM_GetProgramInfo(exheader, prog_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FSREG_GetProgramInfo(exheader, 1, prog_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Result loader_LoadProcess(Handle *process, u64 prog_handle)
|
||||
{
|
||||
Result res;
|
||||
int count;
|
||||
u32 flags;
|
||||
u32 desc;
|
||||
u32 dummy;
|
||||
prog_addrs_t shared_addr;
|
||||
prog_addrs_t vaddr;
|
||||
Handle codeset;
|
||||
CodeSetInfo codesetinfo;
|
||||
u32 data_mem_size;
|
||||
u64 progid;
|
||||
|
||||
// make sure the cached info corrosponds to the current prog_handle
|
||||
if (g_cached_prog_handle != prog_handle)
|
||||
{
|
||||
res = loader_GetProgramInfo(&g_exheader, prog_handle);
|
||||
g_cached_prog_handle = prog_handle;
|
||||
if (res < 0)
|
||||
{
|
||||
g_cached_prog_handle = 0;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// get kernel flags
|
||||
flags = 0;
|
||||
for (count = 0; count < 28; count++)
|
||||
{
|
||||
desc = g_exheader.arm11kernelcaps.descriptors[count];
|
||||
if (0x1FE == desc >> 23)
|
||||
{
|
||||
flags = desc & 0xF00;
|
||||
}
|
||||
}
|
||||
if (flags == 0)
|
||||
{
|
||||
return MAKERESULT(RL_PERMANENT, RS_INVALIDARG, 1, 2);
|
||||
}
|
||||
|
||||
// allocate process memory
|
||||
vaddr.text_addr = g_exheader.codesetinfo.text.address;
|
||||
vaddr.text_size = (g_exheader.codesetinfo.text.codesize + 4095) >> 12;
|
||||
vaddr.ro_addr = g_exheader.codesetinfo.ro.address;
|
||||
vaddr.ro_size = (g_exheader.codesetinfo.ro.codesize + 4095) >> 12;
|
||||
vaddr.data_addr = g_exheader.codesetinfo.data.address;
|
||||
vaddr.data_size = (g_exheader.codesetinfo.data.codesize + 4095) >> 12;
|
||||
data_mem_size = (g_exheader.codesetinfo.data.codesize + g_exheader.codesetinfo.bsssize + 4095) >> 12;
|
||||
vaddr.total_size = vaddr.text_size + vaddr.ro_size + vaddr.data_size;
|
||||
if ((res = allocate_shared_mem(&shared_addr, &vaddr, flags)) < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
// load code
|
||||
progid = g_exheader.arm11systemlocalcaps.programid;
|
||||
if ((res = load_code(progid, &shared_addr, prog_handle, g_exheader.codesetinfo.flags.flag & 1)) >= 0)
|
||||
{
|
||||
memcpy(&codesetinfo.name, g_exheader.codesetinfo.name, 8);
|
||||
codesetinfo.program_id = progid;
|
||||
codesetinfo.text_addr = vaddr.text_addr;
|
||||
codesetinfo.text_size = vaddr.text_size;
|
||||
codesetinfo.text_size_total = vaddr.text_size;
|
||||
codesetinfo.ro_addr = vaddr.ro_addr;
|
||||
codesetinfo.ro_size = vaddr.ro_size;
|
||||
codesetinfo.ro_size_total = vaddr.ro_size;
|
||||
codesetinfo.rw_addr = vaddr.data_addr;
|
||||
codesetinfo.rw_size = vaddr.data_size;
|
||||
codesetinfo.rw_size_total = data_mem_size;
|
||||
res = svcCreateCodeSet(&codeset, &codesetinfo, (void *)shared_addr.text_addr, (void *)shared_addr.ro_addr, (void *)shared_addr.data_addr);
|
||||
if (res >= 0)
|
||||
{
|
||||
res = svcCreateProcess(process, codeset, g_exheader.arm11kernelcaps.descriptors, count);
|
||||
svcCloseHandle(codeset);
|
||||
if (res >= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
svcControlMemory(&dummy, shared_addr.text_addr, 0, shared_addr.total_size << 12, MEMOP_FREE, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
static Result loader_RegisterProgram(u64 *prog_handle, FS_ProgramInfo *title, FS_ProgramInfo *update)
|
||||
{
|
||||
Result res;
|
||||
u64 prog_id;
|
||||
|
||||
prog_id = title->programId;
|
||||
if (prog_id >> 32 != 0xFFFF0000)
|
||||
{
|
||||
res = FSREG_CheckHostLoadId(prog_id);
|
||||
//if ((res >= 0 && (unsigned)res >> 27) || (res < 0 && ((unsigned)res >> 27)-32))
|
||||
if (R_FAILED(res) || (R_SUCCEEDED(res) && R_LEVEL(res) != RL_SUCCESS))
|
||||
{
|
||||
res = PXIPM_RegisterProgram(prog_handle, title, update);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
if (*prog_handle >> 32 != 0xFFFF0000)
|
||||
{
|
||||
res = FSREG_CheckHostLoadId(*prog_handle);
|
||||
//if ((res >= 0 && (unsigned)res >> 27) || (res < 0 && ((unsigned)res >> 27)-32))
|
||||
if (R_FAILED(res) || (R_SUCCEEDED(res) && R_LEVEL(res) != RL_SUCCESS))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
}
|
||||
|
||||
if ((title->mediaType != update->mediaType) || (prog_id != update->programId))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
res = FSREG_LoadProgram(prog_handle, title);
|
||||
if (R_SUCCEEDED(res))
|
||||
{
|
||||
if (*prog_handle >> 32 == 0xFFFF0000)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
res = FSREG_CheckHostLoadId(*prog_handle);
|
||||
//if ((res >= 0 && (unsigned)res >> 27) || (res < 0 && ((unsigned)res >> 27)-32))
|
||||
if (R_FAILED(res) || (R_SUCCEEDED(res) && R_LEVEL(res) != RL_SUCCESS))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static Result loader_UnregisterProgram(u64 prog_handle)
|
||||
{
|
||||
Result res;
|
||||
|
||||
if (prog_handle >> 32 == 0xFFFF0000)
|
||||
{
|
||||
return FSREG_UnloadProgram(prog_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = FSREG_CheckHostLoadId(prog_handle);
|
||||
//if ((res >= 0 && (unsigned)res >> 27) || (res < 0 && ((unsigned)res >> 27)-32))
|
||||
if (R_FAILED(res) || (R_SUCCEEDED(res) && R_LEVEL(res) != RL_SUCCESS))
|
||||
{
|
||||
return PXIPM_UnregisterProgram(prog_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FSREG_UnloadProgram(prog_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_commands(void)
|
||||
{
|
||||
FS_ProgramInfo title;
|
||||
FS_ProgramInfo update;
|
||||
u32* cmdbuf;
|
||||
u16 cmdid;
|
||||
int res;
|
||||
Handle handle;
|
||||
u64 prog_handle;
|
||||
|
||||
cmdbuf = getThreadCommandBuffer();
|
||||
cmdid = cmdbuf[0] >> 16;
|
||||
res = 0;
|
||||
switch (cmdid)
|
||||
{
|
||||
case 1: // LoadProcess
|
||||
{
|
||||
res = loader_LoadProcess(&handle, *(u64 *)&cmdbuf[1]);
|
||||
cmdbuf[0] = 0x10042;
|
||||
cmdbuf[1] = res;
|
||||
cmdbuf[2] = 16;
|
||||
cmdbuf[3] = handle;
|
||||
break;
|
||||
}
|
||||
case 2: // RegisterProgram
|
||||
{
|
||||
memcpy(&title, &cmdbuf[1], sizeof(FS_ProgramInfo));
|
||||
memcpy(&update, &cmdbuf[5], sizeof(FS_ProgramInfo));
|
||||
res = loader_RegisterProgram(&prog_handle, &title, &update);
|
||||
cmdbuf[0] = 0x200C0;
|
||||
cmdbuf[1] = res;
|
||||
*(u64 *)&cmdbuf[2] = prog_handle;
|
||||
break;
|
||||
}
|
||||
case 3: // UnregisterProgram
|
||||
{
|
||||
if (g_cached_prog_handle == prog_handle)
|
||||
{
|
||||
g_cached_prog_handle = 0;
|
||||
}
|
||||
cmdbuf[0] = 0x30040;
|
||||
cmdbuf[1] = loader_UnregisterProgram(*(u64 *)&cmdbuf[1]);
|
||||
break;
|
||||
}
|
||||
case 4: // GetProgramInfo
|
||||
{
|
||||
prog_handle = *(u64 *)&cmdbuf[1];
|
||||
if (prog_handle != g_cached_prog_handle)
|
||||
{
|
||||
res = loader_GetProgramInfo(&g_exheader, prog_handle);
|
||||
if (res >= 0)
|
||||
{
|
||||
g_cached_prog_handle = prog_handle;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_cached_prog_handle = 0;
|
||||
}
|
||||
}
|
||||
memcpy(&g_ret_buf, &g_exheader, 1024);
|
||||
cmdbuf[0] = 0x40042;
|
||||
cmdbuf[1] = res;
|
||||
cmdbuf[2] = 0x1000002;
|
||||
cmdbuf[3] = (u32) &g_ret_buf;
|
||||
break;
|
||||
}
|
||||
default: // error
|
||||
{
|
||||
cmdbuf[0] = 0x40;
|
||||
cmdbuf[1] = 0xD900182F;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Result should_terminate(int *term_request)
|
||||
{
|
||||
u32 notid;
|
||||
Result ret;
|
||||
|
||||
ret = srvSysReceiveNotification(¬id);
|
||||
if (R_FAILED(ret))
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
if (notid == 0x100) // term request
|
||||
{
|
||||
*term_request = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// this is called before main
|
||||
void __appInit()
|
||||
{
|
||||
srvSysInit();
|
||||
fsregInit();
|
||||
fsldrInit();
|
||||
pxipmInit();
|
||||
}
|
||||
|
||||
// this is called after main exits
|
||||
void __appExit()
|
||||
{
|
||||
pxipmExit();
|
||||
fsldrExit();
|
||||
fsregExit();
|
||||
srvSysExit();
|
||||
}
|
||||
|
||||
// stubs for non-needed pre-main functions
|
||||
void __sync_init();
|
||||
void __sync_fini();
|
||||
void __system_initSyscalls();
|
||||
|
||||
void __ctru_exit(int rc)
|
||||
{
|
||||
__appExit();
|
||||
__sync_fini();
|
||||
svcExitProcess();
|
||||
}
|
||||
|
||||
void initSystem(void (*retAddr)(void))
|
||||
{
|
||||
__sync_init();
|
||||
__system_initSyscalls();
|
||||
__appInit();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Result ret;
|
||||
Handle handle;
|
||||
Handle reply_target;
|
||||
Handle *srv_handle;
|
||||
Handle *notification_handle;
|
||||
s32 index;
|
||||
int i;
|
||||
int term_request;
|
||||
u32* cmdbuf;
|
||||
|
||||
ret = 0;
|
||||
|
||||
srv_handle = &g_handles[1];
|
||||
notification_handle = &g_handles[0];
|
||||
|
||||
if (R_FAILED(srvSysRegisterService(srv_handle, "Loader", MAX_SESSIONS)))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
|
||||
if (R_FAILED(srvSysEnableNotification(notification_handle)))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
|
||||
g_active_handles = 2;
|
||||
g_cached_prog_handle = 0;
|
||||
index = 1;
|
||||
|
||||
reply_target = 0;
|
||||
term_request = 0;
|
||||
do
|
||||
{
|
||||
if (reply_target == 0)
|
||||
{
|
||||
cmdbuf = getThreadCommandBuffer();
|
||||
cmdbuf[0] = 0xFFFF0000;
|
||||
}
|
||||
ret = svcReplyAndReceive(&index, g_handles, g_active_handles, reply_target);
|
||||
|
||||
if (R_FAILED(ret))
|
||||
{
|
||||
// check if any handle has been closed
|
||||
if (ret == 0xC920181A)
|
||||
{
|
||||
if (index == -1)
|
||||
{
|
||||
for (i = 2; i < MAX_SESSIONS+2; i++)
|
||||
{
|
||||
if (g_handles[i] == reply_target)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
svcCloseHandle(g_handles[index]);
|
||||
g_handles[index] = g_handles[g_active_handles-1];
|
||||
g_active_handles--;
|
||||
reply_target = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// process responses
|
||||
reply_target = 0;
|
||||
switch (index)
|
||||
{
|
||||
case 0: // notification
|
||||
{
|
||||
if (R_FAILED(should_terminate(&term_request)))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: // new session
|
||||
{
|
||||
if (R_FAILED(svcAcceptSession(&handle, *srv_handle)))
|
||||
{
|
||||
svcBreak(USERBREAK_ASSERT);
|
||||
}
|
||||
if (g_active_handles < MAX_SESSIONS+2)
|
||||
{
|
||||
g_handles[g_active_handles] = handle;
|
||||
g_active_handles++;
|
||||
}
|
||||
else
|
||||
{
|
||||
svcCloseHandle(handle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: // session
|
||||
{
|
||||
handle_commands();
|
||||
reply_target = g_handles[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (!term_request || g_active_handles != 2);
|
||||
|
||||
srvSysUnregisterService("Loader");
|
||||
svcCloseHandle(*srv_handle);
|
||||
svcCloseHandle(*notification_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,495 +0,0 @@
|
||||
#include <3ds.h>
|
||||
#include <string.h>
|
||||
#include "patcher.h"
|
||||
#include "ifile.h"
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 255
|
||||
#define CONFIG(a) ((config >> (a + 16)) & 1)
|
||||
#define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3)
|
||||
#define BOOTCONFIG(a, b) ((config >> a) & b)
|
||||
#endif
|
||||
|
||||
static u32 config = 0;
|
||||
static u8 secureInfo[0x111] = {0};
|
||||
|
||||
//Quick Search algorithm, adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
|
||||
static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
|
||||
{
|
||||
const u8 *patternc = (const u8 *)pattern;
|
||||
|
||||
//Preprocessing
|
||||
u32 table[256];
|
||||
|
||||
for(u32 i = 0; i < 256; ++i)
|
||||
table[i] = patternSize + 1;
|
||||
for(u32 i = 0; i < patternSize; ++i)
|
||||
table[patternc[i]] = patternSize - i;
|
||||
|
||||
//Searching
|
||||
u32 j = 0;
|
||||
|
||||
while(j <= size - patternSize)
|
||||
{
|
||||
if(memcmp(patternc, startPos + j, patternSize) == 0)
|
||||
return startPos + j;
|
||||
j += table[startPos[j + patternSize]];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, int offset, const void *replace, u32 repSize, u32 count)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
u8 *found = memsearch(start, pattern, size, patSize);
|
||||
|
||||
if(found == NULL) break;
|
||||
|
||||
memcpy(found + offset, replace, repSize);
|
||||
|
||||
u32 at = (u32)(found - start);
|
||||
|
||||
if(at + patSize > size) break;
|
||||
|
||||
size -= at + patSize;
|
||||
start = found + patSize;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags)
|
||||
{
|
||||
FS_Archive archive;
|
||||
FS_Path ppath;
|
||||
|
||||
size_t len = strnlen(path, PATH_MAX);
|
||||
archive.id = id;
|
||||
archive.lowPath.type = PATH_EMPTY;
|
||||
archive.lowPath.size = 1;
|
||||
archive.lowPath.data = (u8 *)"";
|
||||
ppath.type = PATH_ASCII;
|
||||
ppath.data = path;
|
||||
ppath.size = len + 1;
|
||||
|
||||
return IFile_Open(file, archive, ppath, flags);
|
||||
}
|
||||
|
||||
static int loadSecureInfo(void)
|
||||
{
|
||||
if(secureInfo[0] == 0xFF)
|
||||
return 0;
|
||||
|
||||
IFile file;
|
||||
Result ret = fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ);
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
u64 total;
|
||||
|
||||
ret = IFile_Read(&file, &total, secureInfo, 0x111);
|
||||
IFile_Close(&file);
|
||||
if(R_SUCCEEDED(ret) && total == 0x111)
|
||||
secureInfo[0] = 0xFF;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int loadConfig(void)
|
||||
{
|
||||
if(config)
|
||||
return 0;
|
||||
|
||||
IFile file;
|
||||
Result ret = fileOpen(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ);
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
u64 total;
|
||||
|
||||
ret = IFile_Read(&file, &total, &config, 4);
|
||||
IFile_Close(&file);
|
||||
if(R_SUCCEEDED(ret)) config |= 1 << 4;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
|
||||
{
|
||||
/* Here we look for "/aurei/locales/[u64 titleID in hex, uppercase].txt"
|
||||
If it exists it should contain, for example, "EUR IT" */
|
||||
|
||||
char path[] = "/aurei/locales/0000000000000000.txt";
|
||||
|
||||
u32 i = 30;
|
||||
|
||||
while(progId > 0)
|
||||
{
|
||||
static const char hexDigits[] = "0123456789ABCDEF";
|
||||
path[i--] = hexDigits[(u32)(progId & 0xF)];
|
||||
progId >>= 4;
|
||||
}
|
||||
|
||||
IFile file;
|
||||
Result ret = fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ);
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
char buf[6];
|
||||
u64 total;
|
||||
|
||||
ret = IFile_Read(&file, &total, buf, 6);
|
||||
IFile_Close(&file);
|
||||
|
||||
if(!R_SUCCEEDED(ret) || total < 6) return -1;
|
||||
|
||||
for(u32 i = 0; i < 7; ++i)
|
||||
{
|
||||
static const char *regions[] = {"JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"};
|
||||
|
||||
if(memcmp(buf, regions[i], 3) == 0)
|
||||
{
|
||||
*regionId = (u8)i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(u32 i = 0; i < 12; ++i)
|
||||
{
|
||||
static const char *languages[] = {"JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"};
|
||||
|
||||
if(memcmp(buf + 4, languages[i], 2) == 0)
|
||||
{
|
||||
*languageId = (u8)i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u8 *getCfgOffsets(u8 *code, u32 size, u32 *CFGUHandleOffset)
|
||||
{
|
||||
/* HANS:
|
||||
Look for error code which is known to be stored near cfg:u handle
|
||||
this way we can find the right candidate
|
||||
(handle should also be stored right after end of candidate function) */
|
||||
|
||||
u32 n = 0,
|
||||
possible[24];
|
||||
|
||||
for(u8 *pos = code + 4; n < 24 && pos < code + size - 4; pos += 4)
|
||||
{
|
||||
if(*(u32 *)pos == 0xD8A103F9)
|
||||
{
|
||||
for(u32 *l = (u32 *)pos - 4; n < 24 && l < (u32 *)pos + 4; l++)
|
||||
if(*l <= 0x10000000) possible[n++] = *l;
|
||||
}
|
||||
}
|
||||
|
||||
for(u8 *CFGU_GetConfigInfoBlk2_endPos = code; CFGU_GetConfigInfoBlk2_endPos < code + size - 8; CFGU_GetConfigInfoBlk2_endPos += 4)
|
||||
{
|
||||
static const u32 CFGU_GetConfigInfoBlk2_endPattern[] = {0xE8BD8010, 0x00010082};
|
||||
|
||||
//There might be multiple implementations of GetConfigInfoBlk2 but let's search for the one we want
|
||||
u32 *cmp = (u32 *)CFGU_GetConfigInfoBlk2_endPos;
|
||||
|
||||
if(cmp[0] == CFGU_GetConfigInfoBlk2_endPattern[0] && cmp[1] == CFGU_GetConfigInfoBlk2_endPattern[1])
|
||||
{
|
||||
*CFGUHandleOffset = *((u32 *)CFGU_GetConfigInfoBlk2_endPos + 2);
|
||||
|
||||
for(u32 i = 0; i < n; i++)
|
||||
if(possible[i] == *CFGUHandleOffset) return CFGU_GetConfigInfoBlk2_endPos;
|
||||
|
||||
CFGU_GetConfigInfoBlk2_endPos += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void patchCfgGetLanguage(u8 *code, u32 size, u8 languageId, u8 *CFGU_GetConfigInfoBlk2_endPos)
|
||||
{
|
||||
u8 *CFGU_GetConfigInfoBlk2_startPos; //Let's find STMFD SP (there might be a NOP before, but nevermind)
|
||||
|
||||
for(CFGU_GetConfigInfoBlk2_startPos = CFGU_GetConfigInfoBlk2_endPos - 4;
|
||||
CFGU_GetConfigInfoBlk2_startPos >= code && *((u16 *)CFGU_GetConfigInfoBlk2_startPos + 1) != 0xE92D;
|
||||
CFGU_GetConfigInfoBlk2_startPos -= 2);
|
||||
|
||||
for(u8 *languageBlkIdPos = code; languageBlkIdPos < code + size; languageBlkIdPos += 4)
|
||||
{
|
||||
if(*(u32 *)languageBlkIdPos == 0xA0002)
|
||||
{
|
||||
for(u8 *instr = languageBlkIdPos - 8; instr >= languageBlkIdPos - 0x1008 && instr >= code + 4; instr -= 4) //Should be enough
|
||||
{
|
||||
if(instr[3] == 0xEB) //We're looking for BL
|
||||
{
|
||||
u8 *calledFunction = instr;
|
||||
u32 i = 0,
|
||||
found;
|
||||
|
||||
do
|
||||
{
|
||||
u32 low24 = (*(u32 *)calledFunction & 0x00FFFFFF) << 2;
|
||||
u32 signMask = (u32)(-(low24 >> 25)) & 0xFC000000; //Sign extension
|
||||
s32 offset = (s32)(low24 | signMask) + 8; //Branch offset + 8 for prefetch
|
||||
|
||||
calledFunction += offset;
|
||||
|
||||
found = calledFunction >= CFGU_GetConfigInfoBlk2_startPos - 4 && calledFunction <= CFGU_GetConfigInfoBlk2_endPos;
|
||||
i++;
|
||||
}
|
||||
while(i < 2 && !found && calledFunction[3] == 0xEA);
|
||||
|
||||
if(found)
|
||||
{
|
||||
*((u32 *)instr - 1) = 0xE3A00000 | languageId; // mov r0, sp => mov r0, =languageId
|
||||
*(u32 *)instr = 0xE5CD0000; // bl CFGU_GetConfigInfoBlk2 => strb r0, [sp]
|
||||
*((u32 *)instr + 1) = 0xE3B00000; // (1 or 2 instructions) => movs r0, 0 (result code)
|
||||
|
||||
//We're done
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void patchCfgGetRegion(u8 *code, u32 size, u8 regionId, u32 CFGUHandleOffset)
|
||||
{
|
||||
for(u8 *cmdPos = code; cmdPos < code + size - 28; cmdPos += 4)
|
||||
{
|
||||
static const u32 cfgSecureInfoGetRegionCmdPattern[] = {0xEE1D4F70, 0xE3A00802, 0xE5A40080};
|
||||
|
||||
u32 *cmp = (u32 *)cmdPos;
|
||||
|
||||
if(cmp[0] == cfgSecureInfoGetRegionCmdPattern[0] && cmp[1] == cfgSecureInfoGetRegionCmdPattern[1] &&
|
||||
cmp[2] == cfgSecureInfoGetRegionCmdPattern[2] && *((u16 *)cmdPos + 7) == 0xE59F &&
|
||||
*(u32 *)(cmdPos + 20 + *((u16 *)cmdPos + 6)) == CFGUHandleOffset)
|
||||
{
|
||||
*((u32 *)cmdPos + 4) = 0xE3A00000 | regionId; // mov r0, =regionId
|
||||
*((u32 *)cmdPos + 5) = 0xE5C40008; // strb r0, [r4, 8]
|
||||
*((u32 *)cmdPos + 6) = 0xE3B00000; // movs r0, 0 (result code) ('s' not needed but nvm)
|
||||
*((u32 *)cmdPos + 7) = 0xE5840004; // str r0, [r4, 4]
|
||||
|
||||
//The remaining, not patched, function code will do the rest for us
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void patchCode(u64 progId, u8 *code, u32 size)
|
||||
{
|
||||
switch(progId)
|
||||
{
|
||||
case 0x0004003000008F02LL: // USA Menu
|
||||
case 0x0004003000008202LL: // EUR Menu
|
||||
case 0x0004003000009802LL: // JPN Menu
|
||||
case 0x000400300000A102LL: // CHN Menu
|
||||
case 0x000400300000A902LL: // KOR Menu
|
||||
case 0x000400300000B102LL: // TWN Menu
|
||||
{
|
||||
static const u8 regionFreePattern[] = {
|
||||
0x00, 0x00, 0x55, 0xE3, 0x01, 0x10, 0xA0, 0xE3
|
||||
};
|
||||
static const u8 regionFreePatch[] = {
|
||||
0x01, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1
|
||||
};
|
||||
|
||||
//Patch SMDH region checks
|
||||
patchMemory(code, size,
|
||||
regionFreePattern,
|
||||
sizeof(regionFreePattern), -16,
|
||||
regionFreePatch,
|
||||
sizeof(regionFreePatch), 1
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0004013000002C02LL: // NIM
|
||||
{
|
||||
static const u8 blockAutoUpdatesPattern[] = {
|
||||
0x25, 0x79, 0x0B, 0x99
|
||||
};
|
||||
static const u8 blockAutoUpdatesPatch[] = {
|
||||
0xE3, 0xA0
|
||||
};
|
||||
static const u8 skipEshopUpdateCheckPattern[] = {
|
||||
0x30, 0xB5, 0xF1, 0xB0
|
||||
};
|
||||
static const u8 skipEshopUpdateCheckPatch[] = {
|
||||
0x00, 0x20, 0x08, 0x60, 0x70, 0x47
|
||||
};
|
||||
|
||||
//Block silent auto-updates
|
||||
patchMemory(code, size,
|
||||
blockAutoUpdatesPattern,
|
||||
sizeof(blockAutoUpdatesPattern), 0,
|
||||
blockAutoUpdatesPatch,
|
||||
sizeof(blockAutoUpdatesPatch), 1
|
||||
);
|
||||
|
||||
//Skip update checks to access the EShop
|
||||
patchMemory(code, size,
|
||||
skipEshopUpdateCheckPattern,
|
||||
sizeof(skipEshopUpdateCheckPattern), 0,
|
||||
skipEshopUpdateCheckPatch,
|
||||
sizeof(skipEshopUpdateCheckPatch), 1
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0004013000003202LL: // FRIENDS
|
||||
{
|
||||
static const u8 fpdVerPattern[] = {
|
||||
0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01, 0x01
|
||||
};
|
||||
|
||||
u8 *fdpVer = memsearch(code, fpdVerPattern, size, sizeof(fpdVerPattern));
|
||||
|
||||
if(fdpVer != NULL)
|
||||
{
|
||||
fdpVer += sizeof(fpdVerPattern) + 1;
|
||||
|
||||
//Allow online access to work with old friends modules
|
||||
if(*fdpVer < 5) *fdpVer = 5;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0004001000021000LL: // USA MSET
|
||||
case 0x0004001000020000LL: // JPN MSET
|
||||
case 0x0004001000022000LL: // EUR MSET
|
||||
case 0x0004001000026000LL: // CHN MSET
|
||||
case 0x0004001000027000LL: // KOR MSET
|
||||
case 0x0004001000028000LL: // TWN MSET
|
||||
{
|
||||
if(R_SUCCEEDED(loadConfig()) && CONFIG(6))
|
||||
{
|
||||
static const u16 verPattern[] = u"Ver.";
|
||||
const u32 currentNand = BOOTCONFIG(0, 3);
|
||||
const u32 matchingFirm = BOOTCONFIG(2, 1) == (currentNand != 0);
|
||||
|
||||
//Patch Ver. string
|
||||
patchMemory(code, size,
|
||||
verPattern,
|
||||
sizeof(verPattern) - sizeof(u16), 0,
|
||||
!currentNand ? ((matchingFirm) ? u" Sys" : u"SysE") :
|
||||
((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuS") : ((matchingFirm) ? u"Emu2" : u"Em2S")),
|
||||
sizeof(verPattern) - sizeof(u16), 1
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0004013000008002LL: // NS
|
||||
{
|
||||
static const u8 stopCartUpdatesPattern[] = {
|
||||
0x0C, 0x18, 0xE1, 0xD8
|
||||
};
|
||||
static const u8 stopCartUpdatesPatch[] = {
|
||||
0x0B, 0x18, 0x21, 0xC8
|
||||
};
|
||||
|
||||
//Disable updates from foreign carts (makes carts region-free)
|
||||
patchMemory(code, size,
|
||||
stopCartUpdatesPattern,
|
||||
sizeof(stopCartUpdatesPattern), 0,
|
||||
stopCartUpdatesPatch,
|
||||
sizeof(stopCartUpdatesPatch), 2
|
||||
);
|
||||
|
||||
if(R_SUCCEEDED(loadConfig()) && MULTICONFIG(1))
|
||||
{
|
||||
static const u8 cfgN3dsCpuPattern[] = {
|
||||
0x40, 0xA0, 0xE1, 0x07, 0x00
|
||||
};
|
||||
|
||||
u8 *cfgN3dsCpuLoc = memsearch(code, cfgN3dsCpuPattern, size, sizeof(cfgN3dsCpuPattern));
|
||||
|
||||
//Patch N3DS CPU Clock and L2 cache setting
|
||||
if(cfgN3dsCpuLoc != NULL)
|
||||
{
|
||||
*(u32 *)(cfgN3dsCpuLoc + 3) = 0xE1A00000;
|
||||
*(u32 *)(cfgN3dsCpuLoc + 0x1F) = 0xE3A00000 | MULTICONFIG(1);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0004013000001702LL: // CFG
|
||||
{
|
||||
static const u8 secureinfoSigCheckPattern[] = {
|
||||
0x06, 0x46, 0x10, 0x48, 0xFC
|
||||
};
|
||||
static const u8 secureinfoSigCheckPatch[] = {
|
||||
0x00, 0x26
|
||||
};
|
||||
|
||||
//Disable SecureInfo signature check
|
||||
patchMemory(code, size,
|
||||
secureinfoSigCheckPattern,
|
||||
sizeof(secureinfoSigCheckPattern), 0,
|
||||
secureinfoSigCheckPatch,
|
||||
sizeof(secureinfoSigCheckPatch), 1
|
||||
);
|
||||
|
||||
if(R_SUCCEEDED(loadSecureInfo()))
|
||||
{
|
||||
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
|
||||
static const u16 secureinfoFilenamePatch[] = u"C";
|
||||
|
||||
//Use SecureInfo_C
|
||||
patchMemory(code, size,
|
||||
secureinfoFilenamePattern,
|
||||
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
||||
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
||||
secureinfoFilenamePatch,
|
||||
sizeof(secureinfoFilenamePatch) - sizeof(u16), 2
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
if(R_SUCCEEDED(loadConfig()) && CONFIG(4))
|
||||
{
|
||||
u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24;
|
||||
|
||||
if(tidHigh == 0x0004000)
|
||||
{
|
||||
//Language emulation
|
||||
u8 regionId = 0xFF,
|
||||
languageId = 0xFF;
|
||||
|
||||
int ret = loadTitleLocaleConfig(progId, ®ionId, &languageId);
|
||||
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
u32 CFGUHandleOffset;
|
||||
|
||||
u8 *CFGU_GetConfigInfoBlk2_endPos = getCfgOffsets(code, size, &CFGUHandleOffset);
|
||||
|
||||
if(CFGU_GetConfigInfoBlk2_endPos != NULL)
|
||||
{
|
||||
if(languageId != 0xFF) patchCfgGetLanguage(code, size, languageId, CFGU_GetConfigInfoBlk2_endPos);
|
||||
if(regionId != 0xFF) patchCfgGetRegion(code, size, regionId, CFGUHandleOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
void patchCode(u64 progId, u8 *code, u32 size);
|
||||
@@ -1,74 +0,0 @@
|
||||
#include <3ds.h>
|
||||
#include <string.h>
|
||||
#include "pxipm.h"
|
||||
#include "srvsys.h"
|
||||
|
||||
static Handle pxipmHandle;
|
||||
static int pxipmRefCount;
|
||||
|
||||
Result pxipmInit(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
|
||||
if (AtomicPostIncrement(&pxipmRefCount)) return 0;
|
||||
|
||||
ret = srvSysGetServiceHandle(&pxipmHandle, "PxiPM");
|
||||
|
||||
if (R_FAILED(ret)) AtomicDecrement(&pxipmRefCount);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void pxipmExit(void)
|
||||
{
|
||||
if (AtomicDecrement(&pxipmRefCount)) return;
|
||||
svcCloseHandle(pxipmHandle);
|
||||
}
|
||||
|
||||
Result PXIPM_RegisterProgram(u64 *prog_handle, FS_ProgramInfo *title, FS_ProgramInfo *update)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,8,0); // 0x20200
|
||||
memcpy(&cmdbuf[1], &title->programId, sizeof(u64));
|
||||
*(u8 *)&cmdbuf[3] = title->mediaType;
|
||||
memcpy(((u8 *)&cmdbuf[3])+1, &title->padding, 7);
|
||||
memcpy(&cmdbuf[5], &update->programId, sizeof(u64));
|
||||
*(u8 *)&cmdbuf[7] = update->mediaType;
|
||||
memcpy(((u8 *)&cmdbuf[7])+1, &update->padding, 7);
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pxipmHandle))) return ret;
|
||||
*prog_handle = *(u64*)&cmdbuf[2];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PXIPM_GetProgramInfo(exheader_header *exheader, u64 prog_handle)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,2,2); // 0x10082
|
||||
cmdbuf[1] = (u32) (prog_handle);
|
||||
cmdbuf[2] = (u32) (prog_handle >> 32);
|
||||
cmdbuf[3] = (0x400 << 8) | 0x4;
|
||||
cmdbuf[4] = (u32) exheader;
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pxipmHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result PXIPM_UnregisterProgram(u64 prog_handle)
|
||||
{
|
||||
u32 *cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x3,2,0); // 0x30080
|
||||
cmdbuf[1] = (u32) (prog_handle);
|
||||
cmdbuf[2] = (u32) (prog_handle >> 32);
|
||||
|
||||
Result ret = 0;
|
||||
if(R_FAILED(ret = svcSendSyncRequest(pxipmHandle))) return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include "exheader.h"
|
||||
|
||||
Result pxipmInit(void);
|
||||
void pxipmExit(void);
|
||||
Result PXIPM_RegisterProgram(u64 *prog_handle, FS_ProgramInfo *title, FS_ProgramInfo *update);
|
||||
Result PXIPM_GetProgramInfo(exheader_header *exheader, u64 prog_handle);
|
||||
Result PXIPM_UnregisterProgram(u64 prog_handle);
|
||||
@@ -1,154 +0,0 @@
|
||||
#include <3ds.h>
|
||||
#include <string.h>
|
||||
#include "srvsys.h"
|
||||
|
||||
static Handle srvHandle;
|
||||
static int srvRefCount;
|
||||
static RecursiveLock initLock;
|
||||
static int initLockinit = 0;
|
||||
|
||||
Result srvSysInit()
|
||||
{
|
||||
Result rc = 0;
|
||||
|
||||
if (!initLockinit)
|
||||
{
|
||||
RecursiveLock_Init(&initLock);
|
||||
}
|
||||
|
||||
RecursiveLock_Lock(&initLock);
|
||||
|
||||
if (srvRefCount > 0)
|
||||
{
|
||||
RecursiveLock_Unlock(&initLock);
|
||||
return MAKERESULT(RL_INFO, RS_NOP, 25, RD_ALREADY_INITIALIZED);
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
rc = svcConnectToPort(&srvHandle, "srv:");
|
||||
if (R_LEVEL(rc) != RL_PERMANENT ||
|
||||
R_SUMMARY(rc) != RS_NOTFOUND ||
|
||||
R_DESCRIPTION(rc) != RD_NOT_FOUND
|
||||
) break;
|
||||
svcSleepThread(500000);
|
||||
}
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
rc = srvSysRegisterClient();
|
||||
srvRefCount++;
|
||||
}
|
||||
|
||||
RecursiveLock_Unlock(&initLock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result srvSysRegisterClient(void)
|
||||
{
|
||||
Result rc = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x1,0,2); // 0x10002
|
||||
cmdbuf[1] = IPC_Desc_CurProcessHandle();
|
||||
|
||||
if(R_FAILED(rc = svcSendSyncRequest(srvHandle)))return rc;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result srvSysExit()
|
||||
{
|
||||
Result rc;
|
||||
RecursiveLock_Lock(&initLock);
|
||||
|
||||
if (srvRefCount > 1)
|
||||
{
|
||||
srvRefCount--;
|
||||
RecursiveLock_Unlock(&initLock);
|
||||
return MAKERESULT(RL_INFO, RS_NOP, 25, RD_BUSY);
|
||||
}
|
||||
|
||||
if (srvHandle != 0) svcCloseHandle(srvHandle);
|
||||
else svcBreak(USERBREAK_ASSERT);
|
||||
rc = (Result)srvHandle; // yeah, I think this is a benign bug
|
||||
srvHandle = 0;
|
||||
srvRefCount--;
|
||||
RecursiveLock_Unlock(&initLock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result srvSysGetServiceHandle(Handle* out, const char* name)
|
||||
{
|
||||
Result rc = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x5,4,0); // 0x50100
|
||||
strncpy((char*) &cmdbuf[1], name,8);
|
||||
cmdbuf[3] = strlen(name);
|
||||
cmdbuf[4] = 0x0;
|
||||
|
||||
if(R_FAILED(rc = svcSendSyncRequest(srvHandle)))return rc;
|
||||
|
||||
if(out) *out = cmdbuf[3];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result srvSysEnableNotification(Handle* semaphoreOut)
|
||||
{
|
||||
Result rc = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x2,0,0);
|
||||
|
||||
if(R_FAILED(rc = svcSendSyncRequest(srvHandle)))return rc;
|
||||
|
||||
if(semaphoreOut) *semaphoreOut = cmdbuf[3];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result srvSysReceiveNotification(u32* notificationIdOut)
|
||||
{
|
||||
Result rc = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0xB,0,0); // 0xB0000
|
||||
|
||||
if(R_FAILED(rc = svcSendSyncRequest(srvHandle)))return rc;
|
||||
|
||||
if(notificationIdOut) *notificationIdOut = cmdbuf[2];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result srvSysRegisterService(Handle* out, const char* name, int maxSessions)
|
||||
{
|
||||
Result rc = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x3,4,0); // 0x30100
|
||||
strncpy((char*) &cmdbuf[1], name,8);
|
||||
cmdbuf[3] = strlen(name);
|
||||
cmdbuf[4] = maxSessions;
|
||||
|
||||
if(R_FAILED(rc = svcSendSyncRequest(srvHandle)))return rc;
|
||||
|
||||
if(out) *out = cmdbuf[3];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result srvSysUnregisterService(const char* name)
|
||||
{
|
||||
Result rc = 0;
|
||||
u32* cmdbuf = getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0] = IPC_MakeHeader(0x4,3,0); // 0x400C0
|
||||
strncpy((char*) &cmdbuf[1], name,8);
|
||||
cmdbuf[3] = strlen(name);
|
||||
|
||||
if(R_FAILED(rc = svcSendSyncRequest(srvHandle)))return rc;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* @file srv.h
|
||||
* @brief Service API.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/// Initializes the service API.
|
||||
Result srvSysInit(void);
|
||||
|
||||
/// Exits the service API.
|
||||
Result srvSysExit(void);
|
||||
|
||||
/**
|
||||
* @brief Retrieves a service handle, retrieving from the environment handle list if possible.
|
||||
* @param out Pointer to write the handle to.
|
||||
* @param name Name of the service.
|
||||
*/
|
||||
Result srvSysGetServiceHandle(Handle* out, const char* name);
|
||||
|
||||
/// Registers the current process as a client to the service API.
|
||||
Result srvSysRegisterClient(void);
|
||||
|
||||
/**
|
||||
* @brief Enables service notificatios, returning a notification semaphore.
|
||||
* @param semaphoreOut Pointer to output the notification semaphore to.
|
||||
*/
|
||||
Result srvSysEnableNotification(Handle* semaphoreOut);
|
||||
|
||||
/**
|
||||
* @brief Receives a notification.
|
||||
* @param notificationIdOut Pointer to output the ID of the received notification to.
|
||||
*/
|
||||
Result srvSysReceiveNotification(u32* notificationIdOut);
|
||||
|
||||
/**
|
||||
* @brief Registers the current process as a service.
|
||||
* @param out Pointer to write the service handle to.
|
||||
* @param name Name of the service.
|
||||
* @param maxSessions Maximum number of sessions the service can handle.
|
||||
*/
|
||||
Result srvSysRegisterService(Handle* out, const char* name, int maxSessions);
|
||||
|
||||
/**
|
||||
* @brief Unregisters the current process as a service.
|
||||
* @param name Name of the service.
|
||||
*/
|
||||
Result srvSysUnregisterService(const char* name);
|
||||
143
k11_extension/Makefile
Normal file
143
k11_extension/Makefile
Normal file
@@ -0,0 +1,143 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITARM)/base_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source source/svc
|
||||
DATA := data
|
||||
INCLUDES := include include/svc
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||
DEFINES := -DARM11 -D_3DS
|
||||
|
||||
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
||||
-Wno-main $(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE)
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(TOPDIR)/linker.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS :=
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).elf
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
%.elf: $(OFILES)
|
||||
@echo linking $(notdir $@)
|
||||
@$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
|
||||
@$(NM) -CSn $@ > $(notdir $*.lst)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
38
k11_extension/include/config.h
Normal file
38
k11_extension/include/config.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define MAKE_BRANCH(src,dst) (0xEA000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
#define MAKE_BRANCH_LINK(src,dst) (0xEB000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
|
||||
#define CONFIG(a) (((cfwInfo.config >> (a)) & 1) != 0)
|
||||
#define MULTICONFIG(a) ((cfwInfo.multiConfig >> (2 * (a))) & 3)
|
||||
#define BOOTCONFIG(a, b) ((cfwInfo.bootConfig >> (a)) & (b))
|
||||
|
||||
#define BOOTCFG_NAND BOOTCONFIG(0, 7)
|
||||
#define BOOTCFG_FIRM BOOTCONFIG(3, 7)
|
||||
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(6, 1)
|
||||
#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(7, 1)
|
||||
|
||||
enum multiOptions
|
||||
{
|
||||
DEFAULTEMU = 0,
|
||||
BRIGHTNESS,
|
||||
SPLASH,
|
||||
SPLASH_DURATION,
|
||||
PIN,
|
||||
NEWCPU
|
||||
};
|
||||
|
||||
enum singleOptions
|
||||
{
|
||||
AUTOBOOTEMU = 0,
|
||||
USEEMUFIRM,
|
||||
LOADEXTFIRMSANDMODULES,
|
||||
PATCHGAMES,
|
||||
PATCHVERSTRING,
|
||||
SHOWGBABOOT,
|
||||
PATCHUNITINFO,
|
||||
DISABLEARM11EXCHANDLERS,
|
||||
ENABLESAFEFIRMROSALINA,
|
||||
};
|
||||
39
k11_extension/include/debug.h
Normal file
39
k11_extension/include/debug.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "globals.h"
|
||||
#include "kernel.h"
|
||||
#include "utils.h"
|
||||
|
||||
extern KRecursiveLock dbgParamsLock;
|
||||
extern u32 dbgParamWatchpointId, dbgParamDVA, dbgParamWCR, dbgParamContextId;
|
||||
|
||||
KSchedulableInterruptEvent *enableMonitorModeDebugging(KBaseInterruptEvent *this, u32 interruptID);
|
||||
KSchedulableInterruptEvent *disableWatchpoint(KBaseInterruptEvent *this, u32 interruptID);
|
||||
KSchedulableInterruptEvent *setWatchpointWithContextId(KBaseInterruptEvent *this, u32 interruptID);
|
||||
52
k11_extension/include/fatalExceptionHandlers.h
Normal file
52
k11_extension/include/fatalExceptionHandlers.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
bool isExceptionFatal(u32 spsr, u32 *regs, u32 index);
|
||||
bool isDataAbortExceptionRangeControlled(u32 spsr, u32 addr);
|
||||
|
||||
void FIQHandler(void);
|
||||
void undefinedInstructionHandler(void);
|
||||
void prefetchAbortHandler(void);
|
||||
void dataAbortHandler(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 magic[2];
|
||||
u16 versionMinor, versionMajor;
|
||||
|
||||
u16 processor, core;
|
||||
u32 type;
|
||||
|
||||
u32 totalSize;
|
||||
u32 registerDumpSize;
|
||||
u32 codeDumpSize;
|
||||
u32 stackDumpSize;
|
||||
u32 additionalDataSize;
|
||||
} ExceptionDumpHeader;
|
||||
139
k11_extension/include/globals.h
Normal file
139
k11_extension/include/globals.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
#include "kernel.h"
|
||||
|
||||
extern KRecursiveLock *criticalSectionLock;
|
||||
extern KObjectList *threadList;
|
||||
extern KObjectMutex *synchronizationMutex;
|
||||
|
||||
extern void (*KRecursiveLock__Lock)(KRecursiveLock *this);
|
||||
extern void (*KRecursiveLock__Unlock)(KRecursiveLock *this);
|
||||
|
||||
extern void (*KAutoObject__AddReference)(KAutoObject *this);
|
||||
|
||||
extern KProcess * (*KProcessHandleTable__ToKProcess)(KProcessHandleTable *this, Handle processHandle);
|
||||
extern KThread * (*KProcessHandleTable__ToKThread)(KProcessHandleTable *this, Handle threadHandle);
|
||||
extern KAutoObject * (*KProcessHandleTable__ToKAutoObject)(KProcessHandleTable *this, Handle handle);
|
||||
extern void (*KSynchronizationObject__Signal)(KSynchronizationObject *this, bool isPulse);
|
||||
extern Result (*WaitSynchronization1)(void *this_unused, KThread *thread, KSynchronizationObject *syncObject, s64 timeout);
|
||||
extern Result (*KProcessHandleTable__CreateHandle)(KProcessHandleTable *this, Handle *out, KAutoObject *obj, u8 token);
|
||||
extern Result (*KProcessHwInfo__MapProcessMemory)(KProcessHwInfo *this, KProcessHwInfo *other, void *dst, void *src, u32 nbPages);
|
||||
extern Result (*KProcessHwInfo__UnmapProcessMemory)(KProcessHwInfo *this, void *addr, u32 nbPages);
|
||||
extern Result (*KEvent__Clear)(KEvent *this);
|
||||
extern void (*KObjectMutex__WaitAndAcquire)(KObjectMutex *this);
|
||||
extern void (*KObjectMutex__ErrorOccured)(void);
|
||||
|
||||
extern void (*KScheduler__AdjustThread)(KScheduler *this, KThread *thread, u32 oldSchedulingMask);
|
||||
extern void (*KScheduler__AttemptSwitchingThreadContext)(KScheduler *this);
|
||||
|
||||
extern Result (*ControlMemory)(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||
extern void (*SleepThread)(s64 ns);
|
||||
extern Result (*CloseHandle)(Handle handle);
|
||||
extern Result (*GetHandleInfo)(s64 *out, Handle handle, u32 type);
|
||||
extern Result (*GetSystemInfo)(s64 *out, s32 type, s32 param);
|
||||
extern Result (*GetProcessInfo)(s64 *out, Handle processHandle, u32 type);
|
||||
extern Result (*GetThreadInfo)(s64 *out, Handle threadHandle, u32 type);
|
||||
extern Result (*ConnectToPort)(Handle *out, const char *name);
|
||||
extern Result (*SendSyncRequest)(Handle handle);
|
||||
extern Result (*OpenProcess)(Handle *out, u32 processId);
|
||||
extern Result (*GetProcessId)(u32 *out, Handle process);
|
||||
extern Result (*DebugActiveProcess)(Handle *out, u32 processId);
|
||||
extern Result (*UnmapProcessMemory)(Handle processHandle, void *dst, u32 size);
|
||||
extern Result (*KernelSetState)(u32 type, u32 varg1, u32 varg2, u32 varg3);
|
||||
|
||||
extern void (*flushDataCacheRange)(void *addr, u32 len);
|
||||
extern void (*invalidateInstructionCacheRange)(void *addr, u32 len);
|
||||
|
||||
extern bool (*usrToKernelMemcpy8)(void *dst, const void *src, u32 len);
|
||||
extern bool (*usrToKernelMemcpy32)(u32 *dst, const u32 *src, u32 len);
|
||||
extern s32 (*usrToKernelStrncpy)(char *dst, const char *src, u32 len);
|
||||
extern bool (*kernelToUsrMemcpy8)(void *dst, const void *src, u32 len);
|
||||
extern bool (*kernelToUsrMemcpy32)(u32 *dst, const u32 *src, u32 len);
|
||||
extern s32 (*kernelToUsrStrncpy)(char *dst, const char *src, u32 len);
|
||||
|
||||
extern void (*svcFallbackHandler)(u8 svcId);
|
||||
extern void (*kernelpanic)(void);
|
||||
extern void (*officialPostProcessSvc)(void);
|
||||
|
||||
extern Result (*SignalDebugEvent)(DebugEventType type, u32 info, ...);
|
||||
|
||||
extern bool isN3DS;
|
||||
extern u32 *exceptionStackTop;
|
||||
|
||||
extern u32 TTBCR;
|
||||
extern u32 L1MMUTableAddrs[4];
|
||||
|
||||
extern void *kernelUsrCopyFuncsStart, *kernelUsrCopyFuncsEnd;
|
||||
|
||||
extern bool *isDevUnit;
|
||||
|
||||
extern vu8 *configPage;
|
||||
extern u32 kernelVersion;
|
||||
extern FcramLayout fcramLayout;
|
||||
|
||||
extern KCoreContext *coreCtxs;
|
||||
|
||||
extern void *originalHandlers[8];
|
||||
extern u32 nbSection0Modules;
|
||||
|
||||
extern u8 __start__[], __end__[], __bss_start__[], __bss_end__[];
|
||||
|
||||
extern Result (*InterruptManager__MapInterrupt)(InterruptManager *manager, KBaseInterruptEvent *iEvent, u32 interruptID,
|
||||
u32 coreID, u32 priority, bool disableUponReceipt, bool levelHighActive);
|
||||
extern InterruptManager *interruptManager;
|
||||
extern KBaseInterruptEvent *customInterruptEvent;
|
||||
|
||||
extern void (*initFPU)(void);
|
||||
extern void (*mcuReboot)(void);
|
||||
extern void (*coreBarrier)(void);
|
||||
|
||||
typedef struct CfwInfo
|
||||
{
|
||||
char magic[4];
|
||||
|
||||
u8 versionMajor;
|
||||
u8 versionMinor;
|
||||
u8 versionBuild;
|
||||
u8 flags;
|
||||
|
||||
u32 commitHash;
|
||||
|
||||
u16 configFormatVersionMajor, configFormatVersionMinor;
|
||||
u32 config, multiConfig, bootConfig;
|
||||
u64 hbldr3dsxTitleId;
|
||||
u32 rosalinaMenuCombo;
|
||||
} CfwInfo;
|
||||
|
||||
extern CfwInfo cfwInfo;
|
||||
extern u32 kextBasePa;
|
||||
extern u32 stolenSystemMemRegionSize;
|
||||
|
||||
extern vu32 rosalinaState;
|
||||
extern bool hasStartedRosalinaNetworkFuncsOnce;
|
||||
60
k11_extension/include/ipc.h
Normal file
60
k11_extension/include/ipc.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of Luma3DS
|
||||
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "globals.h"
|
||||
#include "kernel.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define MAX_SESSION 345
|
||||
|
||||
// the structure of sessions is apparently not the same on older versions...
|
||||
|
||||
typedef struct SessionInfo
|
||||
{
|
||||
KSession *session;
|
||||
char name[12];
|
||||
} SessionInfo;
|
||||
|
||||
typedef struct LangemuAttributes
|
||||
{
|
||||
u64 titleId;
|
||||
u8 mask, region, language, country, state;
|
||||
} LangemuAttributes;
|
||||
|
||||
extern KRecursiveLock processLangemuLock;
|
||||
extern LangemuAttributes processLangemuAttributes[0x40];
|
||||
|
||||
SessionInfo *SessionInfo_Lookup(KSession *session);
|
||||
SessionInfo *SessionInfo_FindFirst(const char *name);
|
||||
void SessionInfo_ChangeVtable(KSession *session);
|
||||
void SessionInfo_Add(KSession *session, const char *name);
|
||||
void SessionInfo_Remove(KSession *session);
|
||||
|
||||
bool doLangEmu(Result *res, u32 *cmdbuf);
|
||||
bool doErrfThrowHook(u32 *cmdbuf);
|
||||
1224
k11_extension/include/kernel.h
Normal file
1224
k11_extension/include/kernel.h
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user