mirror of
https://github.com/LumaTeam/Luma3DS.git
synced 2026-02-22 18:04:38 +00:00
Compare commits
1745 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e35972ea82 | ||
|
|
21f0d64ee8 | ||
|
|
7f1dd962af | ||
|
|
a608ad8241 | ||
|
|
c04c7254ed | ||
|
|
db639a80c9 | ||
|
|
4cfca3c55d | ||
|
|
d3d9a63bf2 | ||
|
|
407c18e6fd | ||
|
|
456a6b4ad7 | ||
|
|
b3282abbf7 | ||
|
|
119499d28d | ||
|
|
12b15812f2 | ||
|
|
55d694fbdd | ||
|
|
1c980b95dc | ||
|
|
da66af3f8a | ||
|
|
97cc70d35d | ||
|
|
59543da23d | ||
|
|
581e591070 | ||
|
|
8a6b766894 | ||
|
|
5f848124c4 | ||
|
|
b4273f9569 | ||
|
|
856a4b3acf | ||
|
|
043e2d2497 | ||
|
|
b15e5fa8d6 | ||
|
|
1399d7ef3b | ||
|
|
60b244d6a3 | ||
|
|
92e586cb3c | ||
|
|
9b8a95a1de | ||
|
|
684c95c7e8 | ||
|
|
2a7caa366e | ||
|
|
d2bf10733b | ||
|
|
78fe559eb6 | ||
|
|
0d0a549967 | ||
|
|
e96f2efc7e | ||
|
|
d299558b09 | ||
|
|
3253fdb255 | ||
|
|
e0e86c46a7 | ||
|
|
902f306ab3 | ||
|
|
ef1773ef4a | ||
|
|
7e4a106787 | ||
|
|
2ae3c4d4ce | ||
|
|
946eb94f02 | ||
|
|
0a11d29d8b | ||
|
|
1c737d499f | ||
|
|
2aa2013318 | ||
|
|
a7bd3208a5 | ||
|
|
14e462be20 | ||
|
|
9f933954a0 | ||
|
|
ab7e8676b5 | ||
|
|
f0be624792 | ||
|
|
85c1997f2b | ||
|
|
2c49a04516 | ||
|
|
2ddf5d334c | ||
|
|
db4564a3f5 | ||
|
|
7a259a5792 | ||
|
|
988ec17ebf | ||
|
|
52a1f4ae60 | ||
|
|
1c7a2b6135 | ||
|
|
cc46e16d66 | ||
|
|
725823a9d9 | ||
|
|
41dd8bd226 | ||
|
|
6c324e0ed0 | ||
|
|
45dce14f23 | ||
|
|
2df3c389c1 | ||
|
|
175e184089 | ||
|
|
df1f9dbfc2 | ||
|
|
64293f8942 | ||
|
|
23e478d67a | ||
|
|
5928eefe95 | ||
|
|
63fbc37426 | ||
|
|
85e0257289 | ||
|
|
35a7ca25b1 | ||
|
|
36df6d6a98 | ||
|
|
bef642c04f | ||
|
|
8cc294b3cb | ||
|
|
a3c5746e06 | ||
|
|
e2778a45cf | ||
|
|
3b64e25402 | ||
|
|
6a2e1d4aa3 | ||
|
|
c0e0f02443 | ||
|
|
a9fcca52d0 | ||
|
|
035c50c625 | ||
|
|
5989d9d61d | ||
|
|
37572f3a48 | ||
|
|
41eccacd51 | ||
|
|
0f09900a2a | ||
|
|
dd22a0cd93 | ||
|
|
3ecce3fc3e | ||
|
|
f40a1cc47b | ||
|
|
11be450894 | ||
|
|
a03988b05d | ||
|
|
497e1904d5 | ||
|
|
41edcde5c0 | ||
|
|
cf3cf12414 | ||
|
|
c055fb6f5e | ||
|
|
b20c79eda4 | ||
|
|
97418ca9a1 | ||
|
|
9fa1d42aa8 | ||
|
|
5b417189db | ||
|
|
06c3215546 | ||
|
|
82d689b485 | ||
|
|
631dddeff8 | ||
|
|
64eda63132 | ||
|
|
3e6399490c | ||
|
|
4025f252c7 | ||
|
|
985380c0d8 | ||
|
|
dc7edbd44f | ||
|
|
ef1072f996 | ||
|
|
89f77db986 | ||
|
|
2e08b7b44f | ||
|
|
1d7cca25d1 | ||
|
|
1888e17b22 | ||
|
|
dfeda19451 | ||
|
|
5a5332a212 | ||
|
|
9957d6db1a | ||
|
|
e7a4003f06 | ||
|
|
faa4a0d4f9 | ||
|
|
777b43b285 | ||
|
|
35e6c5ace9 | ||
|
|
088cf6b673 | ||
|
|
7b97af473a | ||
|
|
ceea6afa05 | ||
|
|
eb6d8523d1 | ||
|
|
ee9f283d4d | ||
|
|
8dd40158ca | ||
|
|
e2e38d9b9f | ||
|
|
7397c85434 | ||
|
|
6592b516a4 | ||
|
|
571592ca7c | ||
|
|
19f7ef372b | ||
|
|
635235c86c | ||
|
|
a812990f0d | ||
|
|
d09bfaf348 | ||
|
|
5cdbfab54b | ||
|
|
da0b1a1389 | ||
|
|
fe4bb0857b | ||
|
|
0a6b6865ca | ||
|
|
ffbd8554d5 | ||
|
|
7074ac1166 | ||
|
|
6fa80c959d | ||
|
|
a7b840e531 | ||
|
|
fcd08d6614 | ||
|
|
71cf677b00 | ||
|
|
0c3f51815e | ||
|
|
80aee6fdc1 | ||
|
|
2c184cf7a3 | ||
|
|
3227b2ea4b | ||
|
|
e5e09c1e13 | ||
|
|
4de0375bde | ||
|
|
ea8f9f4667 | ||
|
|
6573fc4247 | ||
|
|
65825020ab | ||
|
|
e17ff09713 | ||
|
|
b79717e848 | ||
|
|
c0eaf1ea3c | ||
|
|
0e16e4c5fc | ||
|
|
32d13dc117 | ||
|
|
d957494d45 | ||
|
|
1e95344588 | ||
|
|
cb398f1e4a | ||
|
|
ef842dda2a | ||
|
|
56be46b4bd | ||
|
|
f32f3a4854 | ||
|
|
859b11a27d | ||
|
|
97ec1298e3 | ||
|
|
188d86cb7f | ||
|
|
01ebbf114c | ||
|
|
2b5da40a1d | ||
|
|
c64f94bc82 | ||
|
|
3463effeae | ||
|
|
c71474a668 | ||
|
|
90d6420f38 | ||
|
|
676bbf0d88 | ||
|
|
d798ff0efc | ||
|
|
fcdb6a7ab5 | ||
|
|
bc6e14ada7 | ||
|
|
44c1711805 | ||
|
|
ee16c0b104 | ||
|
|
26ea031f0e | ||
|
|
8c3ae4a2fe | ||
|
|
8cfc0bc709 | ||
|
|
fd4d54a2cc | ||
|
|
e9b8b0daef | ||
|
|
b83a0abb9d | ||
|
|
689de1b9f0 | ||
|
|
352a59fd29 | ||
|
|
01661bb1e6 | ||
|
|
caadb3ae5d | ||
|
|
8e9a3bfc74 | ||
|
|
99a2b8e3b2 | ||
|
|
50c81f8165 | ||
|
|
84e64220ab | ||
|
|
a3be4673b1 | ||
|
|
9e3e01b6ac | ||
|
|
4ae4d16dba | ||
|
|
3afecb064c | ||
|
|
7a0ff659a8 | ||
|
|
18f3783f52 | ||
|
|
36ea48b4dc | ||
|
|
b5b5db6e8c | ||
|
|
be6d64260c | ||
|
|
505a17bba1 | ||
|
|
883c5e25dd | ||
|
|
2a947b5c42 | ||
|
|
a9c021d1c9 | ||
|
|
57c4d022ab | ||
|
|
12ed3ae65f | ||
|
|
f54c709f64 | ||
|
|
168647e0f8 | ||
|
|
2fcd2d862d | ||
|
|
cb4a23a2ba | ||
|
|
87fa35ccfd | ||
|
|
df62e1901e | ||
|
|
c058e3f446 | ||
|
|
94b5113b17 | ||
|
|
ebeef7ab7f | ||
|
|
804268916a | ||
|
|
b15becb37a | ||
|
|
8c7f31bb4d | ||
|
|
a7ce156f59 | ||
|
|
67ad6d425a | ||
|
|
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 | ||
|
|
a11124a3d6 | ||
|
|
d2d6e786c7 | ||
|
|
a76c943c01 | ||
|
|
3c64a3a234 | ||
|
|
06060c67b5 | ||
|
|
0f64fd73ec | ||
|
|
2323528975 | ||
|
|
22b38a0f88 | ||
|
|
034c0f8d7c | ||
|
|
b4cd67cb8c | ||
|
|
be83d77187 | ||
|
|
615cf81a9f | ||
|
|
c60ef7fe82 | ||
|
|
fea5a111a9 | ||
|
|
7eebfd4f6a | ||
|
|
939965b5a0 | ||
|
|
a0334120a6 | ||
|
|
308417a48e | ||
|
|
85533411c9 | ||
|
|
6d4a84a325 | ||
|
|
89350b1edd | ||
|
|
9e58e4ed7a | ||
|
|
f8f4ecea27 | ||
|
|
e9449f86bf | ||
|
|
4fabe1f704 | ||
|
|
ef3ba896d5 | ||
|
|
649b160292 | ||
|
|
697bc74535 | ||
|
|
0e9ff44746 | ||
|
|
49d49e637a | ||
|
|
b3f0d13aa4 | ||
|
|
bd1547710e | ||
|
|
7479bf8092 | ||
|
|
d4d281bb9c | ||
|
|
68bf134017 | ||
|
|
c7b90f739f | ||
|
|
160bc36ae8 | ||
|
|
464bf1680c | ||
|
|
c51eaba18c | ||
|
|
7dbded99a2 | ||
|
|
6351e5b8c3 | ||
|
|
5a0f2e4dfc | ||
|
|
6d06ea6975 | ||
|
|
4180261f1f | ||
|
|
e882dd7aaf | ||
|
|
9e851d2dfd | ||
|
|
21a3edb150 | ||
|
|
3aacbd17ce | ||
|
|
6f8a9421ef | ||
|
|
bb437f6f7b | ||
|
|
0001f301f8 | ||
|
|
f7bbc4bfec | ||
|
|
a127a38438 | ||
|
|
16225b97d7 | ||
|
|
0587c14162 | ||
|
|
a181bba9f2 | ||
|
|
993e564fbb | ||
|
|
956829864c | ||
|
|
24186a7148 | ||
|
|
3475cfe1e6 | ||
|
|
6b64a10362 | ||
|
|
5e99fb3aa0 | ||
|
|
060d8e9945 | ||
|
|
1026471842 | ||
|
|
645208ec82 | ||
|
|
f4c48a64ca | ||
|
|
c80ac985fe | ||
|
|
ac9bdc7665 | ||
|
|
217d75024d | ||
|
|
12e5b4adb9 | ||
|
|
945f80993b | ||
|
|
5f32779ceb | ||
|
|
e8ebb2f7fe | ||
|
|
034e63669a | ||
|
|
c75ed567fc | ||
|
|
1e2bf61dcf | ||
|
|
de4fea77a1 | ||
|
|
441c143b3e | ||
|
|
feff28a4fe | ||
|
|
b3d25ce64a | ||
|
|
0f44205959 | ||
|
|
1861d556a6 | ||
|
|
9b1df43687 | ||
|
|
56e0157d64 | ||
|
|
d23cd5acd5 | ||
|
|
39a9eb5ccb | ||
|
|
c413b6d07f | ||
|
|
85a59264c9 | ||
|
|
7f96e47b4f | ||
|
|
02b5c69802 | ||
|
|
b5eb108393 | ||
|
|
0a9cd09cc3 | ||
|
|
af451b4997 | ||
|
|
a5f8ccc3ea | ||
|
|
28cdcfed9c | ||
|
|
ea3e45d40a | ||
|
|
8daf3ebe3f | ||
|
|
7ad55ed61e | ||
|
|
96e46b2234 | ||
|
|
094b88b6aa | ||
|
|
03a6e343db | ||
|
|
b42f9ffb41 | ||
|
|
39280e397a | ||
|
|
887707ea87 | ||
|
|
279f39bc13 | ||
|
|
b7b734bad1 | ||
|
|
d01d9b53f2 | ||
|
|
c542bc5cf3 | ||
|
|
1f5b824c27 | ||
|
|
cb84a6c7ea | ||
|
|
61564e5fcf | ||
|
|
a437e533f5 | ||
|
|
6b88953517 | ||
|
|
9b9f784c26 | ||
|
|
6dfb33191f | ||
|
|
078fce4b3d | ||
|
|
dcb09a9472 | ||
|
|
8ce395caa5 | ||
|
|
e9410c86b1 | ||
|
|
42885560ed | ||
|
|
796e4dd060 | ||
|
|
9468582d83 | ||
|
|
6707a36ffe | ||
|
|
09cc7c903c | ||
|
|
9be7481c14 | ||
|
|
9f68ce0d70 | ||
|
|
4748c0292c | ||
|
|
c3ebce1666 | ||
|
|
b1a428f6bc | ||
|
|
3e0b928db0 | ||
|
|
09380a19ff | ||
|
|
04978ebb01 | ||
|
|
478ebeadf8 | ||
|
|
13fd33a61d | ||
|
|
4bdba9f8e9 | ||
|
|
99829b3cf7 | ||
|
|
d4a3ce2d0d | ||
|
|
a58cb05f2c | ||
|
|
9ab6d107b4 | ||
|
|
42cbead456 | ||
|
|
90ebe78c8e | ||
|
|
bf81ec252e | ||
|
|
899ad1887a | ||
|
|
cb06cf83ff | ||
|
|
aede5a5331 | ||
|
|
5a41663ddc | ||
|
|
7f6ef45f37 | ||
|
|
32e2b85f3a | ||
|
|
6fe748f58c | ||
|
|
e74eda16ce | ||
|
|
eea2076123 | ||
|
|
23fd26630f | ||
|
|
e53c186144 |
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.xml text eol=lf
|
||||||
|
*.ini text eol=lf
|
||||||
96
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
96
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
---
|
||||||
|
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.17.0-50U SysNAND, 11.17.0-50E 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. v13.2.1 stable or if using non-releases specify the commit like this https://github.com/LumaTeam/Luma3DS/commit/988ec17ebfce513fc4589f7b12e0d6e3894ae542]
|
||||||
|
|
||||||
|
**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.-->
|
||||||
|
|
||||||
|
Hbmenu autoboot: ( )
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
Autoboot EmuNAND: ( )
|
||||||
|
<!--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: ( )
|
||||||
|
|
||||||
|
Redirect app. syscore threads to core2: ( )
|
||||||
|
<!--This option is only available on New 3DS (XL)/New 2DS XL.-->
|
||||||
|
|
||||||
|
Show NAND or user string in System Settings: ( )
|
||||||
|
|
||||||
|
Show GBA boot screen in patched AGB_FIRM: ( )
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
|
|
||||||
|
**Explanation of the issue:**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Steps to reproduce:**
|
||||||
|
|
||||||
|
1.
|
||||||
|
|
||||||
|
2.
|
||||||
|
|
||||||
|
|
||||||
|
**Dump file (if applicable):**
|
||||||
|
<!--If the issue leads to a crash you must ensure the "Disable Arm11 exception handlers"
|
||||||
|
-- option is not disabled in config.ini.
|
||||||
|
-- The error message will tell you where the dump is.
|
||||||
|
-- Zip the dmp file and drag & drop it below.-->
|
||||||
24
.gitignore
vendored
24
.gitignore
vendored
@ -1,12 +1,24 @@
|
|||||||
|
.vscode
|
||||||
out
|
out
|
||||||
CakeHax
|
|
||||||
CakeBrah
|
|
||||||
build
|
build
|
||||||
data
|
arm11/build
|
||||||
|
sysmodules/loader/build
|
||||||
|
sysmodules/rosalina/build
|
||||||
|
chainloader/build
|
||||||
|
exceptions/arm9/build
|
||||||
|
exceptions/arm11/build
|
||||||
*.bin
|
*.bin
|
||||||
*.3dsx
|
*.firm
|
||||||
*.smdh
|
|
||||||
*.o
|
*.o
|
||||||
*.d
|
*.d
|
||||||
*.elf
|
*.elf
|
||||||
*.bat
|
*.cxi
|
||||||
|
*.3dsx
|
||||||
|
.DS_Store
|
||||||
|
*.dmp
|
||||||
|
.project
|
||||||
|
.cproject
|
||||||
|
.settings
|
||||||
|
|
||||||
|
Luma3DS*.zip
|
||||||
|
hbmenu.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
@ -1 +0,0 @@
|
|||||||
Subproject commit aca4aa7d3b3d2d195788c0b2555b307fbac63a7f
|
|
||||||
1
CakeHax
1
CakeHax
@ -1 +0,0 @@
|
|||||||
Subproject commit 6b8fca0b37a370a605f76b34b133da91a0b40f5e
|
|
||||||
147
Makefile
147
Makefile
@ -1,131 +1,48 @@
|
|||||||
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
|
ifneq ($(strip $(shell firmtool -v 2>&1 | grep usage)),)
|
||||||
|
$(error "Please install firmtool v1.1 or greater")
|
||||||
CC := arm-none-eabi-gcc
|
|
||||||
AS := arm-none-eabi-as
|
|
||||||
LD := arm-none-eabi-ld
|
|
||||||
OC := arm-none-eabi-objcopy
|
|
||||||
OPENSSL := openssl
|
|
||||||
|
|
||||||
PYTHON3 := python
|
|
||||||
PYTHON_VER_MAJOR := $(word 2, $(subst ., , $(shell python --version 2>&1)))
|
|
||||||
ifneq ($(PYTHON_VER_MAJOR), 3)
|
|
||||||
PYTHON3 := py -3
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
name := ReiNand
|
# Disable kext and firmlaunch patches, all custom sysmodules except Loader, enable PASLR.
|
||||||
|
# Dangerous. Don't enable this unless you know what you're doing!
|
||||||
|
export BUILD_FOR_EXPLOIT_DEV ?= 0
|
||||||
|
|
||||||
dir_source := source
|
# Build with O0 & frame pointer information for use with GDB
|
||||||
dir_data := data
|
export BUILD_FOR_GDB ?= 0
|
||||||
dir_build := build
|
|
||||||
dir_mset := CakeHax
|
|
||||||
dir_out := out
|
|
||||||
dir_emu := emunand
|
|
||||||
dir_reboot := reboot
|
|
||||||
dir_ninjhax := CakeBrah
|
|
||||||
|
|
||||||
ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
|
# Default 3DSX TitleID for hb:ldr
|
||||||
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2
|
export HBLDR_DEFAULT_3DSX_TID ?= 000400000D921E00
|
||||||
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) --no-print-directory
|
|
||||||
|
|
||||||
objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
# What to call the title corresponding to HBLDR_DEFAULT_3DSX_TID
|
||||||
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
|
export HBLDR_DEFAULT_3DSX_TITLE_NAME ?= "hblauncher_loader"
|
||||||
$(call rwildcard, $(dir_source), *.s *.c)))
|
|
||||||
|
|
||||||
|
NAME := $(notdir $(CURDIR))
|
||||||
|
REVISION := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/')
|
||||||
|
|
||||||
.PHONY: all
|
SUBFOLDERS := sysmodules arm11 arm9 k11_extension
|
||||||
all: launcher a9lh emunand emunando3ds reboot rebootntr ninjhax
|
|
||||||
|
|
||||||
.PHONY: launcher
|
.PHONY: all release clean $(SUBFOLDERS)
|
||||||
launcher: $(dir_out)/$(name).dat
|
|
||||||
|
|
||||||
.PHONY: a9lh
|
all: boot.firm
|
||||||
a9lh: $(dir_out)/arm9loaderhax.bin
|
|
||||||
|
|
||||||
.PHONY: emunand
|
release: $(NAME)$(REVISION).zip
|
||||||
emunand: $(dir_out)/rei-n3ds/emunand/emunand.bin
|
|
||||||
|
|
||||||
.PHONY: emunando3ds
|
|
||||||
emunando3ds: $(dir_out)/rei-o3ds/emunand/emunand.bin
|
|
||||||
|
|
||||||
.PHONY: reboot
|
|
||||||
reboot: $(dir_out)/rei-o3ds/reboot/reboot1.bin $(dir_out)/rei-o3ds/reboot/reboot2.bin
|
|
||||||
|
|
||||||
.PHONY: rebootntr
|
|
||||||
rebootntr: $(dir_out)/ntr-o3ds/reboot/reboot1.bin $(dir_out)/ntr-o3ds/reboot/reboot2.bin
|
|
||||||
|
|
||||||
.PHONY: ninjhax
|
|
||||||
ninjhax: $(dir_out)/3ds/$(name)
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
clean:
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_mset) clean
|
@$(foreach dir, $(SUBFOLDERS), $(MAKE) -C $(dir) clean &&) true
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_ninjhax) clean
|
@rm -rf *.firm *.zip *.3dsx
|
||||||
rm -rf $(dir_out) $(dir_build)
|
|
||||||
|
|
||||||
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)/rei-n3ds/ $(dir_out)/rei-o3ds/
|
# boot.3dsx comes from https://github.com/fincs/new-hbmenu/releases
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher
|
$(NAME)$(REVISION).zip: hbmenu.zip boot.firm
|
||||||
dd if=$(dir_build)/main.bin of=$@ bs=512 seek=144
|
@cp $< $@
|
||||||
|
@zip $@ boot.firm -x "*.DS_Store*" "*__MACOSX*"
|
||||||
|
|
||||||
$(dir_out)/arm9loaderhax.bin: $(dir_build)/main.bin $(dir_out)/rei-n3ds/ $(dir_out)/rei-o3ds/
|
boot.firm: $(SUBFOLDERS)
|
||||||
@cp -av $(dir_build)/main.bin $(dir_out)/arm9loaderhax.bin
|
@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)/3ds/$(name):
|
hbmenu.zip:
|
||||||
@mkdir -p "$(dir_out)/3ds/$(name)"
|
@curl -sSfL $(shell curl -s https://api.github.com/repos/devkitPro/3ds-hbmenu/releases/latest | grep 'browser_' | cut -d\" -f4) -o $@
|
||||||
@$(MAKE) $(FLAGS) -C $(dir_ninjhax)
|
@echo downloaded... $(notdir $@)
|
||||||
@mv $(dir_out)/$(name).3dsx $@
|
|
||||||
@mv $(dir_out)/$(name).smdh $@
|
|
||||||
|
|
||||||
$(dir_out)/rei-n3ds/:
|
$(SUBFOLDERS):
|
||||||
@mkdir -p "$(dir_out)/rei-n3ds"
|
@$(MAKE) -C $@ all
|
||||||
|
|
||||||
$(dir_out)/rei-o3ds/:
|
|
||||||
@mkdir -p "$(dir_out)/rei-o3ds"
|
|
||||||
|
|
||||||
$(dir_out)/rei-n3ds/emunand/emunand.bin: $(dir_emu)/emuCode.s
|
|
||||||
@armips $<
|
|
||||||
@mkdir -p "$(dir_out)/rei-n3ds/emunand"
|
|
||||||
@cp -av emunand.bin $(dir_out)/rei-n3ds/emunand
|
|
||||||
|
|
||||||
$(dir_out)/rei-o3ds/emunand/emunand.bin: emunand.bin
|
|
||||||
@mkdir -p "$(dir_out)/rei-o3ds/emunand"
|
|
||||||
@mv emunand.bin $(dir_out)/rei-o3ds/emunand
|
|
||||||
|
|
||||||
$(dir_out)/rei-o3ds/reboot/reboot1.bin: $(dir_reboot)/rebootCode.s
|
|
||||||
@armips $<
|
|
||||||
@mkdir -p "$(dir_out)/rei-o3ds/reboot"
|
|
||||||
@mv reboot1.bin $(dir_out)/rei-o3ds/reboot
|
|
||||||
|
|
||||||
$(dir_out)/rei-o3ds/reboot/reboot2.bin: reboot2.bin
|
|
||||||
@cp -av reboot2.bin $(dir_out)/rei-o3ds/reboot
|
|
||||||
|
|
||||||
$(dir_out)/ntr-o3ds/reboot/reboot1.bin: $(dir_reboot)/rebootCodeNtr.s
|
|
||||||
@armips $<
|
|
||||||
@mkdir -p "$(dir_out)/ntr-o3ds/reboot"
|
|
||||||
@mv reboot1.bin $(dir_out)/ntr-o3ds/reboot
|
|
||||||
|
|
||||||
$(dir_out)/ntr-o3ds/reboot/reboot2.bin: reboot2.bin
|
|
||||||
@mv reboot2.bin $(dir_out)/ntr-o3ds/reboot
|
|
||||||
|
|
||||||
$(dir_build)/main.bin: $(dir_build)/main.elf
|
|
||||||
$(OC) -S -O binary $< $@
|
|
||||||
|
|
||||||
$(dir_build)/main.elf: $(objects_cfw)
|
|
||||||
# FatFs requires libgcc for __aeabi_uidiv
|
|
||||||
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
|
||||||
|
|
||||||
$(dir_build)/%.o: $(dir_source)/%.c
|
|
||||||
@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) -mthumb -mthumb-interwork -Wno-unused-function $(OUTPUT_OPTION) $<
|
|
||||||
|
|
||||||
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s
|
|
||||||
@mkdir -p "$(@D)"
|
|
||||||
$(COMPILE.s) -mthumb -mthumb-interwork $(OUTPUT_OPTION) $<
|
|
||||||
include $(call rwildcard, $(dir_build), *.d)
|
|
||||||
|
|||||||
114
README.md
114
README.md
@ -1,24 +1,112 @@
|
|||||||
# AuReiNand
|
# Luma3DS
|
||||||
*A modification of the ReiNand custom firmware*
|
|
||||||
|
|
||||||
**Compiling:**
|

|
||||||
|

|
||||||
|
|
||||||
You'll need armips added to your Path. [HERE](https://www.dropbox.com/s/ceuv2qeqp38lpah/armips.exe?dl=0) is a pre-compiled version.
|
*Nintendo 3DS "Custom Firmware"*
|
||||||
|
|
||||||
Lastly, just run Make and everything should work!
|

|
||||||
|

|
||||||
|
|
||||||
Copy everything in 'out' folder to SD root and run!
|
## Description
|
||||||
|
**Luma3DS** patches and reimplements significant parts of the system software running on all models of the Nintendo 3DS family of consoles. It aims to greatly improve the user experience and support the 3DS far beyond its end-of-life. Features include:
|
||||||
|
|
||||||
**Usage / Features:**
|
* **First-class support for homebrew applications**
|
||||||
|
* **Rosalina**, an overlay menu (triggered by <kbd>L+Down+Select</kbd> by default), allowing things like:
|
||||||
|
* Taking screenshots while in game
|
||||||
|
* Blue light filters and other screen filters
|
||||||
|
* Input redirection to play with external devices, such as controllers
|
||||||
|
* Using cheat codes
|
||||||
|
* Setting time and date accurately from the network (NTP)
|
||||||
|
* ... and much more!
|
||||||
|
* **Many game modding features**, such as, but not limited to:
|
||||||
|
* Game plugins (in 3GX format)
|
||||||
|
* Per-game language overrides ("locale emulation")
|
||||||
|
* Asset content path redirection ("LayeredFS")
|
||||||
|
* **Support for user-provided patches and/or full "system modules" replacements**, an essential feature for Nintendo Network replacements (amongst other projects)
|
||||||
|
* A **fully-fledged GDB stub**, allowing homebrew developers and reverse-engineers alike to work much more efficiently
|
||||||
|
* Ability to chainload other firmware files, including other versions of itself
|
||||||
|
* ... and much more!
|
||||||
|
|
||||||
See https://github.com/Reisyukaku/ReiNand and http://gbatemp.net/threads/reinand-mod-o3ds-n3ds-sysnand.411110
|
## Installation and upgrade
|
||||||
|
Luma3DS requires [boot9strap](https://github.com/SciresM/boot9strap) to run.
|
||||||
|
|
||||||
The FIRMs you need are here:
|
Once boot9strap has been installed, simply download the [latest release archive](https://github.com/LumaTeam/Luma3DS/releases/latest) and extract the archive onto the root of your SD card to "install" or to upgrade Luma3DS alongside the [homebrew menu and certs bundle](https://github.com/devkitPro/3ds-hbmenu) shipped with it. Replace existing files and merge existing folders if necessary.
|
||||||
|
|
||||||
http://www99.zippyshare.com/v/kEIiQl0x/file.html
|
## Basic usage
|
||||||
|
**The main Luma3DS configuration menu** can be accessed by pressing <kbd>Select</kbd> at boot. The configuration file is stored in `/luma/config.ini` on the SD card (or `/rw/luma/config.ini` on the CTRNAND partition if Luma3DS has been launched from the CTRNAND partition, which happens when SD card is missing).
|
||||||
|
|
||||||
**Credits:**
|
**The chainloader menu** is accessed by pressing <kbd>Start</kbd> at boot, or from the configuration menu. Payloads are expected to be located in `/luma/payloads` with the `.firm` extension; if there is only one such payload, the aforementionned selection menu will be skipped. Hotkeys can be assigned to payload, for example `x_test.firm` will be chainloaded when <kbd>X</kbd> is pressed at boot.
|
||||||
|
|
||||||
Rei as this is 99% his code (this is no more than a mod)
|
**The overlay menu, Rosalina**, has a default button combination: <kbd>L+Down+Select</kbd>. For greater flexbility, most Rosalina menu settings aren't saved automatically, hence the "Save settings" option.
|
||||||
|
|
||||||
Everyone he credited on his GitHub :P
|
**GDB ports**, when enabled, are `4000-4002` for the normal ports. Use of `attach` in "extended-remote" mode, alongside `info os processes` is supported and encouraged (for reverse-engineering, also check out `monitor getmemregions`). The port for the break-on-start feature is `4003` without "extended-remote". Both devkitARM-patched GDB and IDA Pro (without "stepping support" enabled) are actively supported.
|
||||||
|
|
||||||
|
We have a wiki, however it is currently very outdated.
|
||||||
|
|
||||||
|
## Components
|
||||||
|
|
||||||
|
Luma3DS consists of multiple components. While the code style within each component is mostly consistent, these components have been written over many years and may not reflect how maintainers would write new code in new components/projects:
|
||||||
|
|
||||||
|
* **arm9**, **arm11**: baremetal main settings menu, chainloader and firmware loader. Aside from showing settings and chainloading to other homebrew firmware files on demand, it is responsible for patching the official firmware to modify `Process9` code and to inject all other custom components. This was the first component ever written for this project, in 2015
|
||||||
|
* **k11_extension**: code extending the Arm11 `NATIVE_FIRM` kernel (`Kernel11`). It is injected by the above mentioned baremetal loader into the kernel by hooking its startup code, then hooks itself into the rest of the kernel. Its features include hooking system calls (SVCs), introducing new SVCs and hooking into interprocess communications, to bypass limitations in Nintendo's system design. This is the component that allows Rosalina to pause other processes on overlay menu entry, for example. This was written at a time when we didn't fully reverse-engineer the kernel, and originally released in 2017 alongside Rosalina. Further hooks for "game plugin" support have been merged in 2023
|
||||||
|
* **sysmodules**: reimplementation of "system modules" (processes) of the 3DS's OS (except for Rosalina being custom), currently only initial processes loaded directly in-memory by the kernel ("kernel initial process", or KIP in short)
|
||||||
|
* **loader**: process that loads non-KIP processes from storage. Because this is the perfect place to patch/replace executable code, this is where all process patches are done, enabling in particular "game modding" features. This is also the sysmodule handling 3DSX homebrew loading. Introduced in 2016
|
||||||
|
* _**rosalina**_: the most important component of Luma3DS and custom KIP: overlay menu, GDB server, `err:f` (fatal error screen) reimplementation, and much more. Introduced in mid-2017, and has continuously undergone changes and received many external contributions ever since
|
||||||
|
* **pxi**: Arm11<>Arm9 communication KIP, reimplemented just for the sake of it. Introduced late 2017
|
||||||
|
* **sm**: service manager KIP, reimplemented to remove service access control restrictions. Introduced late 2017
|
||||||
|
* **pm**: process manager KIP reponsible of starting/terminating processes and instructing `loader` to load them. The reimplemention allows for break-on-start GDB feature in Rosalina, as well as lifting FS access control restrictions the proper way. Introduced in 2019
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
|
||||||
|
* **[@TuxSH](https://github.com/TuxSH)**: lead developer, created and maintains most features of the project. Joined in 2016
|
||||||
|
* **[@AuroraWright](https://github.com/AuroraWright)**: author of the project, implemented the core features (most of the baremetal boot settings menu and firmware loading code) with successful design decisions that made the project popular. Created the project in 2015, currently inactive
|
||||||
|
* **[@PabloMK7](https://github.com/PabloMK7)**: maintainer of the plugin loader feature merged for the v13.0 release. Joined in 2023
|
||||||
|
|
||||||
|
## Roadmap
|
||||||
|
|
||||||
|
There are still a lot more features and consolidation planned for Luma3DS! Here is a list of what is currently in store:
|
||||||
|
|
||||||
|
* Full reimplementation of `TwlBg` and `AgbBg`. This will allow much better, and more configurable, upscaling for top screen in DS and GBA games (except on Old 2DS). This is currently being developed privately in C++23 (no ETA). While this is quite a difficult endeavor as this requires rewriting the entire driver stack in semi-bare-metal (limited kernel with no IPC), this is the most critical feature for Luma3DS to have and will make driver sysmodule reimpelementation trivial
|
||||||
|
* Reimplementation of `Process9` for `TWL_FIRM` and `AGB_FIRM` to allow for more features in DS and GBA compatibility mode (ones that require file access)
|
||||||
|
* Eventually, a full `Kernel11` reimplementation
|
||||||
|
|
||||||
|
## Known issues
|
||||||
|
|
||||||
|
* **Cheat engine crashes with some applications, in particular Pokémon games**: there is a race condition in Nintendo's `Kernel11` pertaining to attaching a new `KDebugThread` to a `KThread` on thread creation, and another thread null-dereferencing `thread->debugThread`. This causes the cheat engine to crashes games that create and destroy many threads all the time (like Pokémon).
|
||||||
|
* For these games, having a **dedicated "game plugin"** is the only alternative until `Kernel11` is reimplemented.
|
||||||
|
* **Applications reacting to Rosalina menu button combo**: Rosalina merely polls button input at an interval to know when to show the menu. This means that the Rosalina menu combo can sometimes be processed by the game/process that is going to be paused.
|
||||||
|
* You can **change the menu combo** in the "Miscellaneous options" submenu (then save it with "Save settings" in the main menu) to work around this.
|
||||||
|
|
||||||
|
## Building from source
|
||||||
|
|
||||||
|
To build Luma3DS, the following is needed:
|
||||||
|
* git
|
||||||
|
* [makerom](https://github.com/jakcron/Project_CTR) in `$PATH`
|
||||||
|
* [firmtool](https://github.com/TuxSH/firmtool) installed
|
||||||
|
* up-to-date devkitARM and libctru:
|
||||||
|
* install `dkp-pacman` (or, for distributions that already provide pacman, add repositories): https://devkitpro.org/wiki/devkitPro_pacman
|
||||||
|
* install packages from `3ds-dev` metapackage: `sudo dkp-pacman -S 3ds-dev --needed`
|
||||||
|
* while libctru and Luma3DS releases are kept in sync, you may have to build libctru from source for non-release Luma3DS commits
|
||||||
|
|
||||||
|
While Luma3DS releases are bundled with `3ds-hbmenu`, Luma3DS actually compiles into one single file: `boot.firm`. Just copy it over to the root of your SD card ([ftpd](https://github.com/mtheall/ftpd) is the easiest way to do so), and you're done.
|
||||||
|
|
||||||
|
## 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. PM, SM, PXI reimplementations are also licensed under MIT.
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
Luma3DS would not be what it is without the contributions and constructive feedback of many. We would like to thanks in particular:
|
||||||
|
|
||||||
|
* **[@devkitPro](https://github.com/devkitPro)** (especially **[@fincs](https://github.com/fincs)**, **[@WinterMute](https://github.com/WinterMute)** and **[@mtheall](https://github.com/mtheall)**) for providing quality and easy-to-use toolchains with bleeding-edge GCC, and for their continued technical advice
|
||||||
|
* **[@Nanquitas](https://github.com/Nanquitas)** for the initial version of the game plugin loader code as well as very useful contributions to the GDB stub
|
||||||
|
* **[@piepie62](https://github.com/piepie62)** for the current implementation of the Rosalina cheat engine, **Duckbill** for its original implementation
|
||||||
|
* **[@panicbit](https://github.com/panicbit)** for the original implementation of screen filters in Rosalina
|
||||||
|
* **[@jasondellaluce](https://github.com/jasondellaluce)** for LayeredFS
|
||||||
|
* **[@LiquidFenrir](https://github.com/LiquidFenrir)** for the memory viewer inside Rosalina's "Process List"
|
||||||
|
* **ChaN** for [FatFs](http://elm-chan.org/fsw/ff/00index_e.html)
|
||||||
|
* Everyone who has contributed to the Luma3DS repository
|
||||||
|
* Everyone who has assisted with troubleshooting end-users
|
||||||
|
* Everyone who has provided constructive feedback to Luma3DS
|
||||||
|
|||||||
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 --no-warn-rwx-segments
|
||||||
|
|
||||||
|
*startfile:
|
||||||
|
crti%O%s crtbegin%O%s
|
||||||
259
arm11/source/main.c
Normal file
259
arm11/source/main.c
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
// Color LUT
|
||||||
|
*(vu32 *)0x10400480 = 0;
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Color LUT
|
||||||
|
*(vu32 *)0x10400580 = 0;
|
||||||
|
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 *)0x10400578 & 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void zerofillN3dsAblRegisters(void)
|
||||||
|
{
|
||||||
|
// It should be fine to write to these regs even on O3DS as they
|
||||||
|
// are RAZ/WI
|
||||||
|
|
||||||
|
// TODO: read from calibration, but null values should do just
|
||||||
|
// fine. From testing, LUT explicitly ignores null values, and
|
||||||
|
// it is probably the case of reg @ 0x54 as well.
|
||||||
|
*(vu32 *)0x10202250 = 0; // unknown 24-bit value, seen: 0
|
||||||
|
*(vu32 *)0x10202254 = 0; // unknown 24-bit value, seen: nonzero
|
||||||
|
|
||||||
|
*(vu32 *)0x10202A50 = 0; // unknown 24-bit value, seen: 0
|
||||||
|
*(vu32 *)0x10202A54 = 0; // unknown 24-bit value, seen: nonzero
|
||||||
|
|
||||||
|
for (u32 i = 0; i < 64; i++) {
|
||||||
|
// Blend colors (w/ color multiplication) for each group
|
||||||
|
// of 4 relative-luminance Rs
|
||||||
|
*(vu32 *)(0x10202300 + 4*i) = 0;
|
||||||
|
*(vu32 *)(0x10202B00 + 4*i) = 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 ZEROFILL_N3DS_ABL_REGISTERS:
|
||||||
|
zerofillN3dsAblRegisters();
|
||||||
|
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
|
||||||
66
arm11/source/types.h
Normal file
66
arm11/source/types.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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,
|
||||||
|
ZEROFILL_N3DS_ABL_REGISTERS,
|
||||||
|
PREPARE_ARM11_FOR_FIRMLAUNCH,
|
||||||
|
ARM11_READY,
|
||||||
|
} Arm11Operation;
|
||||||
191
arm9/Makefile
Normal file
191
arm9/Makefile
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.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
|
||||||
|
|
||||||
|
# Default 3DSX TitleID for hb:ldr (note: also defined in top-level Makefile)
|
||||||
|
export HBLDR_DEFAULT_3DSX_TID ?= 000400000D921E00
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# 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
|
||||||
|
|
||||||
|
ifeq ($(BUILD_FOR_EXPLOIT_DEV),1)
|
||||||
|
DEFINES := -DARM9 -D__3DS__ -DHBLDR_DEFAULT_3DSX_TID="0x$(HBLDR_DEFAULT_3DSX_TID)ULL" -DBUILD_FOR_EXPLOIT_DEV=1
|
||||||
|
else
|
||||||
|
DEFINES := -DARM9 -D__3DS__ -DHBLDR_DEFAULT_3DSX_TID="0x$(HBLDR_DEFAULT_3DSX_TID)ULL"
|
||||||
|
endif
|
||||||
|
|
||||||
|
FALSEPOSITIVES := -Wno-array-bounds -Wno-stringop-overflow -Wno-stringop-overread
|
||||||
|
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
||||||
|
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
||||||
|
-Wno-main $(FALSEPOSITIVES) $(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
|
||||||
|
patches.o config.o: CFLAGS += -DCONFIG_TITLE="\"$(APP_TITLE) $(REVISION) configuration\""\
|
||||||
|
-DVERSION_MAJOR="$(VERSION_MAJOR)" -DVERSION_MINOR="$(VERSION_MINOR)"\
|
||||||
|
-DVERSION_BUILD="$(VERSION_BUILD)" -DISRELEASE="$(IS_RELEASE)" -DCOMMIT_HASH="0x$(COMMIT)"
|
||||||
|
config.o ini.o: CFLAGS += -DINI_HANDLER_LINENO=1 -DINI_STOP_ON_FIRST_ERROR=1
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# you need a rule like this for each extension you use as binary data
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.bin.o %_bin.h : %.bin
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(bin2o)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.ini.o %_ini.h: %.ini
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(bin2o)
|
||||||
|
|
||||||
|
-include $(DEPENDS)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
BIN
arm9/data/config_template.ini
Normal file
BIN
arm9/data/config_template.ini
Normal file
Binary file not shown.
210
arm9/linker.ld
Normal file
210
arm9/linker.ld
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
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*)
|
||||||
|
KEEP (*(.emunand_patch))
|
||||||
|
|
||||||
|
*(.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 --no-warn-rwx-segments
|
||||||
|
|
||||||
|
*startfile:
|
||||||
|
crti%O%s crtbegin%O%s
|
||||||
181
arm9/source/3dsheaders.h
Normal file
181
arm9/source/3dsheaders.h
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* 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 ExeFsFileHeader
|
||||||
|
{
|
||||||
|
char name[8];
|
||||||
|
u32 offset;
|
||||||
|
u32 size;
|
||||||
|
} ExeFsFileHeader;
|
||||||
|
|
||||||
|
typedef struct ExeFsHeader
|
||||||
|
{
|
||||||
|
ExeFsFileHeader fileHeaders[10];
|
||||||
|
u8 _reserved_0xa0[0xC0 - 0xA0];
|
||||||
|
u8 fileHashes[10][32];
|
||||||
|
} ExeFsHeader;
|
||||||
|
|
||||||
|
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}
|
||||||
112
arm9/source/arm9_exception_handlers.c
Normal file
112
arm9/source/arm9_exception_handlers.c
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
static inline void dumpArm9Memory(ExceptionDumpHeader *dumpHeader, u8 *buf)
|
||||||
|
{
|
||||||
|
// Check if n3ds extra arm9 mem is enabled (if it's possible to read CFG9_EXTMEMCNT9)
|
||||||
|
u8 extmemcnt9 = 0;
|
||||||
|
safecpy(&extmemcnt9, (const void *)0x10000200, 1);
|
||||||
|
|
||||||
|
u32 size = (extmemcnt9 & 1) ? 0x180000 : 0x100000;
|
||||||
|
dumpHeader->additionalDataSize += safecpy(buf, (const void *)0x08000000, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 3;
|
||||||
|
|
||||||
|
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));
|
||||||
|
final += dumpHeader.stackDumpSize;
|
||||||
|
|
||||||
|
// See if we need to copy Arm9 memory (check for bkpt 0xFFFD / bkpt 0xFD)
|
||||||
|
if(dumpHeader.codeDumpSize > 0)
|
||||||
|
{
|
||||||
|
if(cpsr & 0x20)
|
||||||
|
{
|
||||||
|
// Thumb
|
||||||
|
u16 instr;
|
||||||
|
safecpy(&instr, codeDump + dumpHeader.codeDumpSize - 2, 2);
|
||||||
|
if(instr == 0xBEFD) dumpArm9Memory(&dumpHeader, final);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u32 instr;
|
||||||
|
safecpy(&instr, codeDump + dumpHeader.codeDumpSize - 4, 4);
|
||||||
|
if(instr == 0xE12FFF7D) dumpArm9Memory(&dumpHeader, final);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
1209
arm9/source/config.c
Normal file
1209
arm9/source/config.c
Normal file
File diff suppressed because it is too large
Load Diff
84
arm9/source/config.h
Normal file
84
arm9/source/config.h
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#define AUTOBOOT_DEFAULT_TWL_TID 0x0003000448424C41ull
|
||||||
|
|
||||||
|
#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.ini"
|
||||||
|
#define CONFIG_VERSIONMAJOR 3
|
||||||
|
#define CONFIG_VERSIONMINOR 13
|
||||||
|
|
||||||
|
#define BOOTCFG_NAND BOOTCONFIG(0, 1)
|
||||||
|
#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3)
|
||||||
|
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1)
|
||||||
|
#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1)
|
||||||
|
|
||||||
|
enum multiOptions
|
||||||
|
{
|
||||||
|
DEFAULTEMU = 0,
|
||||||
|
BRIGHTNESS,
|
||||||
|
SPLASH,
|
||||||
|
PIN,
|
||||||
|
NEWCPU,
|
||||||
|
AUTOBOOTMODE,
|
||||||
|
FORCEAUDIOOUTPUT,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum singleOptions
|
||||||
|
{
|
||||||
|
AUTOBOOTEMU = 0,
|
||||||
|
LOADEXTFIRMSANDMODULES,
|
||||||
|
PATCHGAMES,
|
||||||
|
REDIRECTAPPTHREADS,
|
||||||
|
PATCHVERSTRING,
|
||||||
|
SHOWGBABOOT,
|
||||||
|
PATCHUNITINFO,
|
||||||
|
ENABLEDSIEXTFILTER,
|
||||||
|
DISABLEARM11EXCHANDLERS,
|
||||||
|
ENABLESAFEFIRMROSALINA,
|
||||||
|
|
||||||
|
NUMCONFIGURABLE = PATCHUNITINFO,
|
||||||
|
};
|
||||||
|
|
||||||
|
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-2021 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 ctrNandLocation = 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 = ctrNandLocation == FIRMWARE_SYSNAND ? sdmmc_nand_readsectors(0, 1, temp) : sdmmc_sdcard_readsectors(emuOffset + 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(ctrNandLocation == 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 ctrNandLocation;
|
||||||
|
|
||||||
|
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);
|
||||||
279
arm9/source/deliver_arg.c
Normal file
279
arm9/source/deliver_arg.c
Normal file
@ -0,0 +1,279 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2022 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 "deliver_arg.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "fs.h"
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
u8 *loadDeliverArg(void)
|
||||||
|
{
|
||||||
|
static __attribute__((aligned(8))) u8 deliverArg[0x1000] = {0};
|
||||||
|
static bool deliverArgLoaded = false;
|
||||||
|
|
||||||
|
if (!deliverArgLoaded)
|
||||||
|
{
|
||||||
|
u32 bootenv = CFG_BOOTENV; // this register is preserved across reboots
|
||||||
|
if ((bootenv & 1) == 0) // true coldboot
|
||||||
|
{
|
||||||
|
memset(deliverArg, 0, 0x1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u32 mode = bootenv >> 1;
|
||||||
|
if (mode == 0) // CTR mode
|
||||||
|
{
|
||||||
|
memcpy(deliverArg, (const void *)0x20000000, 0x1000);
|
||||||
|
|
||||||
|
// Validate deliver arg
|
||||||
|
u32 testPattern = *(u32 *)(deliverArg + 0x438);
|
||||||
|
u32 *crcPtr = (u32 *)(deliverArg + 0x43C);
|
||||||
|
u32 crc = *crcPtr;
|
||||||
|
*crcPtr = 0; // clear crc field before calculation
|
||||||
|
u32 expectedCrc = crc32(deliverArg + 0x400, 0x140, 0xFFFFFFFF);
|
||||||
|
*crcPtr = crc;
|
||||||
|
if (testPattern != 0xFFFF || crc != expectedCrc)
|
||||||
|
memset(deliverArg, 0, 0x1000);
|
||||||
|
}
|
||||||
|
else // Legacy modes
|
||||||
|
{
|
||||||
|
// Copy TWL deliver arg stuff as-is (0...0x300)
|
||||||
|
copyFromLegacyModeFcram(deliverArg, (const void *)0x20000000, 0x400);
|
||||||
|
|
||||||
|
// Validate TLNC (TWL launcher params) block
|
||||||
|
// Note: Nintendo doesn't do crcLen bound check
|
||||||
|
u8 *tlnc = deliverArg + 0x300;
|
||||||
|
bool hasMagic = memcmp(tlnc, "TLNC", 4) == 0;
|
||||||
|
u8 crcLen = tlnc[5];
|
||||||
|
u16 crc = *(u16 *)(tlnc + 6);
|
||||||
|
if (!hasMagic || (8 + crcLen) > 0x100 || crc != crc16(tlnc + 8, crcLen, 0xFFFF))
|
||||||
|
memset(tlnc, 0, 0x100);
|
||||||
|
|
||||||
|
memset(deliverArg + 0x400, 0, 0xC00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deliverArgLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return deliverArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void commitDeliverArg(void)
|
||||||
|
{
|
||||||
|
u8 *deliverArg = loadDeliverArg();
|
||||||
|
u32 bootenv = CFG_BOOTENV;
|
||||||
|
|
||||||
|
if ((bootenv & 1) == 0) // if true coldboot, set bootenv to "CTR mode reboot"
|
||||||
|
{
|
||||||
|
bootenv = 1;
|
||||||
|
CFG_BOOTENV = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 mode = bootenv >> 1;
|
||||||
|
if (mode == 0) // CTR mode
|
||||||
|
{
|
||||||
|
*(u32 *)(deliverArg + 0x438) = 0xFFFF;
|
||||||
|
*(u32 *)(deliverArg + 0x43C) = 0; // clear CRC field before calculating it
|
||||||
|
*(u32 *)(deliverArg + 0x43C) = crc32(deliverArg + 0x400, 0x140, 0xFFFFFFFF);
|
||||||
|
memcpy((void *)0x20000000, deliverArg, 0x1000);
|
||||||
|
}
|
||||||
|
else // Legacy modes (just TWL mode, really)
|
||||||
|
{
|
||||||
|
copyToLegacyModeFcram((void *)0x20000000, deliverArg, 0x400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasValidTlncAutobootParams(void)
|
||||||
|
{
|
||||||
|
u8 *tlnc = loadDeliverArg() + 0x300; // loadDeliverArg clears invalid TLNC blocks
|
||||||
|
return memcmp(tlnc, "TLNC", 4) == 0 && (*(u16 *)(tlnc + 0x18) & 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTwlToCtrLaunch(void)
|
||||||
|
{
|
||||||
|
// assumes TLNC block is valid
|
||||||
|
u8 *tlnc = loadDeliverArg() + 0x300; // loadDeliverArg clears invalid TLNC blocks
|
||||||
|
u64 twlTid = *(u64 *)(tlnc + 0x10);
|
||||||
|
|
||||||
|
switch (twlTid & ~0xFFull)
|
||||||
|
{
|
||||||
|
case 0x0000000000000000ull: // TWL Launcher -> Home menu (note: NS checks full TID)
|
||||||
|
case 0x00030015484E4200ull: // TWL System Settings -> CTR System Settings (mset)
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool configureHomebrewAutobootCtr(u8 *deliverArg)
|
||||||
|
{
|
||||||
|
static const u8 appmemtypesO3ds[] = { 0, 2, 3, 4, 5 };
|
||||||
|
static const u8 appmemtypesN3ds[] = { 6, 7, 7, 7, 7 };
|
||||||
|
|
||||||
|
u64 hbldrTid = configData.hbldr3dsxTitleId;
|
||||||
|
hbldrTid = hbldrTid == 0 ? HBLDR_DEFAULT_3DSX_TID : hbldrTid; // replicate Loader's behavior
|
||||||
|
if ((hbldrTid >> 46) != 0x10) // Not a CTR titleId. Bail out
|
||||||
|
return false;
|
||||||
|
|
||||||
|
u8 memtype = configData.autobootCtrAppmemtype;
|
||||||
|
// autobootCtrAppmemtype already checked, but it doesn't hurt to check again
|
||||||
|
memtype = memtype >= 5 ? 0 : memtype;
|
||||||
|
deliverArg[0x400] = ISN3DS ? appmemtypesN3ds[memtype] : appmemtypesO3ds[memtype];
|
||||||
|
|
||||||
|
// Determine whether to load from the SD card or from NAND. We don't support gamecards for this
|
||||||
|
u32 category = (hbldrTid >> 32) & 0xFFFF;
|
||||||
|
bool isSdApp = (category & 0x10) == 0 && category != 1; // not a system app nor a DLP child
|
||||||
|
*(u64 *)(deliverArg + 0x440) = hbldrTid;
|
||||||
|
*(u64 *)(deliverArg + 0x448) = isSdApp ? 1 : 0;
|
||||||
|
|
||||||
|
// Tell NS to run the title, and that it's not a title jump from legacy mode
|
||||||
|
*(u32 *)(deliverArg + 0x460) = (0 << 1) | (1 << 0);
|
||||||
|
|
||||||
|
// Whenever power button is held long enough ("force shutdown"), mcu sysmodule
|
||||||
|
// stores a flag in free reg 0. It will clear it next boot.
|
||||||
|
|
||||||
|
// During that next boot, if that flag was set and if CFG_BOOTENV.bit0 is set
|
||||||
|
// (warmboot/firm chainload, i.e. not coldbooting), then main() will simulate
|
||||||
|
// a "power button held" interrupt (after upgrading mcu fw if necessary -- it
|
||||||
|
// will reboot console after if it has upgraded mcu fw, I guess that's one of
|
||||||
|
// the reasons the flag is there). This obviously cause other processes to initiate
|
||||||
|
// a shutdown, and it also sets that flag again.
|
||||||
|
|
||||||
|
// In the case of autoboot, ns will panic when this happens. This caused
|
||||||
|
// hb autoboot to keep failing over and over again.
|
||||||
|
|
||||||
|
// Select free reg 0, read it, select it again, write it (clearing force shutdown flag)
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x60, 0);
|
||||||
|
u8 flags = I2C_readReg(I2C_DEV_MCU, 0x61);
|
||||||
|
flags &= ~4;
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x60, 0);
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x61, flags);
|
||||||
|
|
||||||
|
CFG_BOOTENV = 1;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool configureHomebrewAutobootTwl(u8 *deliverArg)
|
||||||
|
{
|
||||||
|
// Here, we pretend to be a TWL app rebooting into another TWL app.
|
||||||
|
// We get NS to do all the heavy lifting (starting NWM and AM, etc.) this way.
|
||||||
|
|
||||||
|
memset(deliverArg + 0x000, 0, 0x300); // zero TWL deliver arg params
|
||||||
|
|
||||||
|
// Now onto TLNC (launcher params):
|
||||||
|
u8 *tlnc = deliverArg + 0x300;
|
||||||
|
memset(tlnc, 0, 0x100);
|
||||||
|
memcpy(tlnc, "TLNC", 4);
|
||||||
|
tlnc[4] = 1; // version
|
||||||
|
tlnc[5] = 0x18; // length of data to calculate CRC over
|
||||||
|
|
||||||
|
*(u64 *)(tlnc + 8) = 0; // old title ID
|
||||||
|
*(u64 *)(tlnc + 0x10) = configData.autobootTwlTitleId; // new title ID
|
||||||
|
// bit4: "skip logo" ; bits2:1: NAND boot ; bit0: valid
|
||||||
|
*(u16 *)(tlnc + 0x18) = (1 << 4) | (3 << 1) | (1 << 0);
|
||||||
|
|
||||||
|
*(u16 *)(tlnc + 6) = crc16(tlnc + 8, 0x18, 0xFFFF);
|
||||||
|
|
||||||
|
// Even though (when running TWL/AGB FIRM) the SoC is in O3DS mode, and the GPU also is,
|
||||||
|
// as well as most other components behaving as such (external RAM, L2C not usable, etc.),
|
||||||
|
// this is NOT the case for the LCD and adaptive backlight logic which retains FULL N3DS
|
||||||
|
// functionality, including a feature where the window is blended with a given color depending
|
||||||
|
// on the overall relative luminance of that window.
|
||||||
|
|
||||||
|
// However, Nintendo's own code mistakenly assumes the opposite, and clearly so ("if GPU in N3DS mode"
|
||||||
|
// checks, not passing N3DS extra adaptive backlight (ABL) to TWL/AGB_FIRM). This has implications:
|
||||||
|
|
||||||
|
// - Powersaving (ABL) settings in TWL/AGB_FIRM is inconsistent with *both* O3DS (because the new RGB blend LUT
|
||||||
|
// has been set to its current value by NATIVE_FIRM) and N3DS (because "pwn_cnt" and "inertia" are missing
|
||||||
|
// their N3DS-only bits)
|
||||||
|
// - "rave party" when booting into TWL/AGB_FIRM or O3DS NATIVE_FIRM without these regs (well, the LUT) initialized.
|
||||||
|
// Easiest way to do so is by leveraging the "DSi autooboot" feature Luma provides. It is worth noting at least
|
||||||
|
// the LUT survives hardware reboots (if Nintendo were using DSi software that was using TLNC-based reboots,
|
||||||
|
// they wouldn't have noticed).
|
||||||
|
|
||||||
|
// As such, zerofill these registers (from testing, hardware explicitly discards null values, so this
|
||||||
|
// should be fine). For now, only touch the Luma-initiated autoboot path
|
||||||
|
|
||||||
|
if (ISN3DS)
|
||||||
|
zerofillN3dsAblRegisters();
|
||||||
|
|
||||||
|
CFG_BOOTENV = 3;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool configureHomebrewAutoboot(void)
|
||||||
|
{
|
||||||
|
bool ret;
|
||||||
|
u8 *deliverArg = loadDeliverArg();
|
||||||
|
|
||||||
|
u32 bootenv = CFG_BOOTENV;
|
||||||
|
u32 mode = bootenv >> 1;
|
||||||
|
|
||||||
|
// NS always writes a valid deliver arg on reboot, no matter what.
|
||||||
|
// Check if it is empty, and, of course, bail out if we aren't rebooting from
|
||||||
|
// NATIVE_FIRM.
|
||||||
|
// Checking if it is empty is necessary to let us reboot from autobooted hbmenu
|
||||||
|
// to hbmenu.
|
||||||
|
|
||||||
|
if (mode != 0)
|
||||||
|
return false;
|
||||||
|
else if (bootenv == 1)
|
||||||
|
{
|
||||||
|
for (u32 i = 0; i < 0x410; i++)
|
||||||
|
{
|
||||||
|
if (deliverArg[i] != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (u32 i = 0x440; i < 0x1000; i++)
|
||||||
|
{
|
||||||
|
if (deliverArg[i] != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (MULTICONFIG(AUTOBOOTMODE))
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
ret = configureHomebrewAutobootCtr(deliverArg);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ret = configureHomebrewAutobootTwl(deliverArg);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
ret = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
commitDeliverArg();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
37
arm9/source/deliver_arg.h
Normal file
37
arm9/source/deliver_arg.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2022 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"
|
||||||
|
|
||||||
|
u8 *loadDeliverArg(void);
|
||||||
|
void commitDeliverArg(void);
|
||||||
|
|
||||||
|
bool hasValidTlncAutobootParams(void);
|
||||||
|
bool isTwlToCtrLaunch(void); // assumes TLNC block is valid
|
||||||
|
|
||||||
|
bool configureHomebrewAutoboot(void);
|
||||||
127
arm9/source/draw.c
Normal file
127
arm9/source/draw.c
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
wait(configData.splashDurationMsec);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
53
arm9/source/draw.h
Normal file
53
arm9/source/draw.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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_GREEN 0x00FF00
|
||||||
|
#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);
|
||||||
|
|
||||||
|
__attribute__((format(printf,5,6)))
|
||||||
|
u32 drawFormattedString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *fmt, ...);
|
||||||
338
arm9/source/emunand.c
Normal file
338
arm9/source/emunand.c
Normal file
@ -0,0 +1,338 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2021 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, u32 *emunandIndex, bool configureCtrNandParams)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (*nandType == FIRMWARE_SYSNAND)
|
||||||
|
return;*/
|
||||||
|
|
||||||
|
for(u32 i = 0; i < 3; i++) // Test the different kinds of multi-EmuNAND there are, unless we are looking for the first one
|
||||||
|
{
|
||||||
|
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 = nandSize > 0x200000 ? 0x400000 : 0x200000; //"Legacy" layout
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nandOffset *= *emunandIndex; // always 0 for 1st EmuNAND
|
||||||
|
|
||||||
|
if(fatStart >= nandOffset + roundedMinsizes[ISN3DS ? 1 : 0])
|
||||||
|
{
|
||||||
|
//Check for RedNAND
|
||||||
|
if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0)
|
||||||
|
{
|
||||||
|
if (configureCtrNandParams)
|
||||||
|
{
|
||||||
|
emuOffset = nandOffset + 1;
|
||||||
|
emuHeader = 0;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check for Gateway EmuNAND
|
||||||
|
else if(i != 2 && !sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && memcmp(temp + 0x100, "NCSD", 4) == 0)
|
||||||
|
{
|
||||||
|
if (configureCtrNandParams)
|
||||||
|
{
|
||||||
|
emuOffset = nandOffset;
|
||||||
|
emuHeader = nandSize;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*emunandIndex == 0) break; // See above comments
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fallback to the first EmuNAND if there's no second/third/fourth one, or to SysNAND if there isn't any
|
||||||
|
if(*emunandIndex != 0)
|
||||||
|
{
|
||||||
|
*emunandIndex = 0;
|
||||||
|
locateEmuNand(nandType, emunandIndex, configureCtrNandParams);
|
||||||
|
}
|
||||||
|
else *nandType = FIRMWARE_SYSNAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32 getProtoSdmmc(u32 *sdmmc, u32 firmVersion)
|
||||||
|
{
|
||||||
|
switch(firmVersion)
|
||||||
|
{
|
||||||
|
case 243: // SDK 0.9.x (0.9.7?)
|
||||||
|
*sdmmc = (0x080AAA28 + 0x4e0);
|
||||||
|
break;
|
||||||
|
case 238: // SDK 0.10
|
||||||
|
*sdmmc = (0x080BEA70 + 0x690);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 hookAddr)
|
||||||
|
{
|
||||||
|
//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] = hookAddr;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32 patchProtoNandRw(u8 *pos, u32 size, u32 hookAddr, u32 hookCidAddr)
|
||||||
|
{
|
||||||
|
//Look for read/write code
|
||||||
|
static const u8 pattern[] = {
|
||||||
|
0x03, 0x00, 0x51, 0xE3, // cmp r1, #3
|
||||||
|
0x02, 0xC0, 0xA0, 0xE1, // mov r12, r2
|
||||||
|
0x04, 0x00, 0x80, 0xE2, // add r0, r0, #4
|
||||||
|
};
|
||||||
|
|
||||||
|
u32 *writeOffset = (u32 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||||
|
|
||||||
|
if(writeOffset == NULL) return 1;
|
||||||
|
|
||||||
|
u32 *readOffset = (u32 *)memsearch((u8 *)(writeOffset + 3), pattern, 0x400, sizeof(pattern));
|
||||||
|
|
||||||
|
if(readOffset == NULL) return 1;
|
||||||
|
|
||||||
|
// Find the sdmmc mount/init(?) function
|
||||||
|
static const u8 mount_pattern[] = {
|
||||||
|
0x20, 0x00, 0x84, 0xE2, // add r0, r4, 0x20
|
||||||
|
0x01, 0x20, 0xA0, 0xE3, // mov r2, #1
|
||||||
|
0x00, 0x10, 0xA0, 0xE3, // mov r1, #0
|
||||||
|
};
|
||||||
|
u32* mountOffset = (u32*) memsearch(pos, mount_pattern, size, sizeof(mount_pattern));
|
||||||
|
if (mountOffset == NULL) return 1;
|
||||||
|
|
||||||
|
// Find the sdmmc read cid function.
|
||||||
|
static const u8 readcid_pattern[] = {
|
||||||
|
0x31, 0xFF, 0x2F, 0xE1, // blx r1
|
||||||
|
0x20, 0x60, 0x9F, 0xE5, // ldr r6, [pc, #0x20] // =failing_result
|
||||||
|
0x00, 0x00, 0x50, 0xE3, // cmp r0, #0
|
||||||
|
};
|
||||||
|
u32* readCidOffset = (u32*) memsearch(pos, readcid_pattern, size, sizeof(readcid_pattern));
|
||||||
|
if (readCidOffset == NULL) return 1;
|
||||||
|
readCidOffset -= 5;
|
||||||
|
|
||||||
|
mountOffset[1] = 0xe3a02000; // mov r2, #0 // sd-card
|
||||||
|
|
||||||
|
readOffset[0] = writeOffset[0] = 0xe52de004; // push {lr}
|
||||||
|
readOffset[1] = writeOffset[1] = 0xe59fc000; // ldr r12, [pc, #0]
|
||||||
|
readOffset[2] = writeOffset[2] = 0xe12fff3c; // blx r12
|
||||||
|
readOffset[3] = writeOffset[3] = hookAddr;
|
||||||
|
|
||||||
|
readCidOffset[0] = 0xe59fc000; // ldr r12, [pc, #0]
|
||||||
|
readCidOffset[1] = 0xe12fff3c; // blx r12
|
||||||
|
readCidOffset[2] = hookCidAddr;
|
||||||
|
|
||||||
|
// Read the emmc cid into the place hook will copy it from
|
||||||
|
sdmmc_get_cid(1, emunandPatchNandCid);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32 patchProtoNandRw238(u8 *pos, u32 size, u32 hookAddr, u32 hookCidAddr)
|
||||||
|
{
|
||||||
|
//Look for read/write code
|
||||||
|
static const u8 pattern[] = {
|
||||||
|
0x03, 0x00, 0x50, 0xE3, // cmp r0, #3
|
||||||
|
0x00, 0x00, 0xA0, 0x13, // movne r0, #0
|
||||||
|
0x01, 0x00, 0xA0, 0x03, // moveq r0, #1
|
||||||
|
};
|
||||||
|
|
||||||
|
u32 *writeOffset = (u32 *)memsearch(pos, pattern, size, sizeof(pattern));
|
||||||
|
|
||||||
|
if(writeOffset == NULL) return 1;
|
||||||
|
|
||||||
|
u32 *readOffset = (u32 *)memsearch((u8 *)(writeOffset + 3), pattern, 0x400, sizeof(pattern));
|
||||||
|
|
||||||
|
if(readOffset == NULL) return 1;
|
||||||
|
|
||||||
|
// Find the mmc static ctor...
|
||||||
|
static const u8 mount_pattern[] = {
|
||||||
|
0x08, // last byte of some ptr to something in P9
|
||||||
|
0x01, 0x01, 0x00, 0x00, // emmc controller id
|
||||||
|
};
|
||||||
|
u8* mountOffset = (u8*) memsearch(pos, mount_pattern, size, sizeof(mount_pattern));
|
||||||
|
if (mountOffset == NULL) return 1;
|
||||||
|
mountOffset++;
|
||||||
|
|
||||||
|
// Find the sdmmc read cid function.
|
||||||
|
static const u8 readcid_pattern[] = {
|
||||||
|
0x31, 0xFF, 0x2F, 0xE1, // blx r1
|
||||||
|
0x20, 0x60, 0x9F, 0xE5, // ldr r6, [pc, #0x20] // =failing_result
|
||||||
|
0x00, 0x00, 0x50, 0xE3, // cmp r0, #0
|
||||||
|
};
|
||||||
|
u32* readCidOffset = (u32*) memsearch(pos, readcid_pattern, size, sizeof(readcid_pattern));
|
||||||
|
if (readCidOffset == NULL) return 1;
|
||||||
|
readCidOffset -= 5;
|
||||||
|
|
||||||
|
*(u32*)mountOffset = 0x300; // sd card
|
||||||
|
|
||||||
|
readOffset[0] = writeOffset[0] = 0xe59fc000; // ldr r12, [pc, #0]
|
||||||
|
readOffset[1] = writeOffset[1] = 0xe12fff3c; // blx r12
|
||||||
|
readOffset[2] = writeOffset[2] = hookAddr;
|
||||||
|
|
||||||
|
readCidOffset[0] = 0xe59fc000; // ldr r12, [pc, #0]
|
||||||
|
readCidOffset[1] = 0xe12fff3c; // blx r12
|
||||||
|
readCidOffset[2] = hookCidAddr;
|
||||||
|
|
||||||
|
// Read the emmc cid into the place hook will copy it from
|
||||||
|
sdmmc_get_cid(1, emunandPatchNandCid);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchEmuNand(u8 *process9Offset, u32 process9Size, u32 firmVersion)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
//Add EmuNAND hooks
|
||||||
|
ret += patchNandRw(process9Offset, process9Size, (u32)emunandPatch);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchProtoEmuNand(u8 *process9Offset, u32 process9Size)
|
||||||
|
{
|
||||||
|
extern u32 firmProtoVersion;
|
||||||
|
u32 ret = 0;
|
||||||
|
|
||||||
|
// Add the data of the found EmuNAND
|
||||||
|
emunandPatchNandOffset = emuOffset;
|
||||||
|
emunandPatchNcsdHeaderOffset = emuHeader;
|
||||||
|
|
||||||
|
// Find and add the SDMMC struct
|
||||||
|
u32 sdmmc;
|
||||||
|
ret += getProtoSdmmc(&sdmmc, firmProtoVersion);
|
||||||
|
if(!ret) emunandPatchSdmmcStructPtr = sdmmc;
|
||||||
|
|
||||||
|
// Add EmuNAND hooks
|
||||||
|
switch (firmProtoVersion) {
|
||||||
|
case 243: // SDK 0.9.x (0.9.7?)
|
||||||
|
ret += patchProtoNandRw(process9Offset, process9Size, (u32)emunandProtoPatch, (u32)emunandProtoCidPatch);
|
||||||
|
break;
|
||||||
|
case 238: // SDK 0.10.x
|
||||||
|
ret += patchProtoNandRw238(process9Offset, process9Size, (u32)emunandProtoPatch238, (u32)emunandProtoCidPatch);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
42
arm9/source/emunand.h
Normal file
42
arm9/source/emunand.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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 *emunandIndex, bool configureCtrNandParams);
|
||||||
|
u32 patchEmuNand(u8 *process9Offset, u32 process9Size, u32 firmVersion);
|
||||||
|
u32 patchProtoEmuNand(u8 *process9Offset, u32 process9Size);
|
||||||
194
arm9/source/emunand_patch.s
Normal file
194
arm9/source/emunand_patch.s
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
.section .emunand_patch, "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
|
||||||
|
|
||||||
|
_emunandPatchEnd:
|
||||||
|
|
||||||
|
.global emunandProtoPatch
|
||||||
|
emunandProtoPatch:
|
||||||
|
@ Save registers
|
||||||
|
push {r0-r3}
|
||||||
|
|
||||||
|
@ If we're already trying to access the SD, return
|
||||||
|
ldr r2, [r0, #4]
|
||||||
|
ldr r1, emunandPatchSdmmcStructPtr
|
||||||
|
cmp r2, r1
|
||||||
|
beq _out
|
||||||
|
|
||||||
|
ldrb r2, [r1, #0xc] @ Get sdmc->m_isInitialised
|
||||||
|
cmp r2, #0 @ Is initialised?
|
||||||
|
beq _pastSdmc @ if not, use "NAND" object, patched elsewhere to access SD
|
||||||
|
str r1, [r0, #4] @ Set object to be SD
|
||||||
|
_pastSdmc:
|
||||||
|
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
|
||||||
|
pop {r0-r3}
|
||||||
|
@ Execute original code that got patched.
|
||||||
|
cmp r1, #3
|
||||||
|
mov r12, r2
|
||||||
|
add r0, r0, #4
|
||||||
|
movne r1, #0
|
||||||
|
moveq r1, #1
|
||||||
|
@ r2 about to be overwritten, so it's free to use here.
|
||||||
|
@ Save off our return address and restore lr.
|
||||||
|
mov r2, lr
|
||||||
|
pop {lr}
|
||||||
|
@ r2+0 is return address (patched movne r1, #0)
|
||||||
|
@ r2+4 is moveq r1, #1
|
||||||
|
@ r2+8 is the following instruction (mov r2, r3)
|
||||||
|
add r2, #8
|
||||||
|
bx r2
|
||||||
|
|
||||||
|
.global emunandProtoCidPatch
|
||||||
|
emunandProtoCidPatch:
|
||||||
|
@ If we're already trying to access the SD, return
|
||||||
|
ldr r4, emunandPatchSdmmcStructPtr
|
||||||
|
cmp r0, r4
|
||||||
|
beq _cid_return
|
||||||
|
|
||||||
|
@ Trying to access nand, so copy the NAND cid into r1
|
||||||
|
adr r4, emunandPatchNandCid
|
||||||
|
ldr r2, [r4, #0]
|
||||||
|
ldr r3, [r4, #4]
|
||||||
|
ldr r5, [r4, #8]
|
||||||
|
ldr r6, [r4, #0xc]
|
||||||
|
str r2, [r1, #0]
|
||||||
|
str r3, [r1, #4]
|
||||||
|
str r5, [r1, #8]
|
||||||
|
str r6, [r1, #0xc]
|
||||||
|
@ And return from whence we came
|
||||||
|
mov r0, #0
|
||||||
|
pop {r4-r6, pc}
|
||||||
|
|
||||||
|
_cid_return:
|
||||||
|
@ Execute original code that got patched.
|
||||||
|
mov r4, r0
|
||||||
|
ldr r0, [r0]
|
||||||
|
mov r5, r1
|
||||||
|
@ lr+0 is return address (patched mov r5, r1)
|
||||||
|
@ lr+4 is following instruction (ldr r1, [r0,#8])
|
||||||
|
add lr, #4
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
.global emunandProtoPatch238
|
||||||
|
emunandProtoPatch238:
|
||||||
|
@ Save registers
|
||||||
|
push {r0-r3}
|
||||||
|
|
||||||
|
@ If we're already trying to access the SD, return
|
||||||
|
ldr r2, [r4, #4]
|
||||||
|
ldr r1, emunandPatchSdmmcStructPtr
|
||||||
|
cmp r2, r1
|
||||||
|
beq _out238
|
||||||
|
|
||||||
|
ldr r2, [r1, #0x24] @ Get sdmc->m_someObjInitedLater
|
||||||
|
cmp r2, #0 @ Is initialised?
|
||||||
|
beq _pastSdmc238 @ if not, use "NAND" object, patched elsewhere to access SD
|
||||||
|
str r1, [r4, #4] @ Set object to be SD
|
||||||
|
_pastSdmc238:
|
||||||
|
|
||||||
|
ldr r2, [r4, #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, [r4, #8] @ Store sector to read
|
||||||
|
|
||||||
|
_out238:
|
||||||
|
@ Restore registers
|
||||||
|
pop {r0-r3}
|
||||||
|
@ Execute original code that got patched.
|
||||||
|
cmp r0, #3
|
||||||
|
movne r0, #0
|
||||||
|
moveq r0, #1
|
||||||
|
@ r1 about to be overwritten, so it's free to use here.
|
||||||
|
@ Save off our return address.
|
||||||
|
mov r1, lr
|
||||||
|
@ r1+0 is return address (patched moveq r1, #1)
|
||||||
|
@ r1+4 is tst r0, #0xff or sub sp, sp, #0xc
|
||||||
|
add r1, #4
|
||||||
|
bx r1
|
||||||
|
|
||||||
|
.pool
|
||||||
|
|
||||||
|
.global emunandPatchSdmmcStructPtr
|
||||||
|
.global emunandPatchNandOffset
|
||||||
|
.global emunandPatchNcsdHeaderOffset
|
||||||
|
.global emunandPatchNandCid
|
||||||
|
|
||||||
|
_emunandPatchBssStart:
|
||||||
|
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)
|
||||||
|
emunandPatchNandCid: @ Store emmc cid here, to override "sdmc's" when trying to read emmc's
|
||||||
|
.word 0,0,0,0
|
||||||
|
_emunandPatchBssEnd:
|
||||||
|
|
||||||
|
.pool
|
||||||
|
.balign 4
|
||||||
|
|
||||||
|
.global emunandPatchSize
|
||||||
|
emunandPatchSize:
|
||||||
|
.word _emunandPatchEnd - emunandPatch
|
||||||
|
|
||||||
|
.global emunandPatchBssSize
|
||||||
|
emunandPatchBssSize:
|
||||||
|
.word _emunandPatchBssEnd - _emunandPatchBssStart
|
||||||
204
arm9/source/exceptions.c
Normal file
204
arm9/source/exceptions.c
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
u32 size = dumpHeader->additionalDataSize;
|
||||||
|
if(dumpHeader->processor == 11)
|
||||||
|
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
|
||||||
|
"Current process: %.8s (%016llX)", (const char *)additionalData, *(vu64 *)(additionalData + 8));
|
||||||
|
else
|
||||||
|
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
|
||||||
|
"Arm9 memory dump at offset %X size %lX", (uintptr_t)additionalData - (uintptr_t)dumpHeader, size);
|
||||||
|
}
|
||||||
|
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);
|
||||||
369
arm9/source/fatfs/00history.txt
Normal file
369
arm9/source/fatfs/00history.txt
Normal file
@ -0,0 +1,369 @@
|
|||||||
|
----------------------------------------------------------------------------
|
||||||
|
Revision history of FatFs module
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
R0.00 (February 26, 2006)
|
||||||
|
|
||||||
|
Prototype.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.01 (April 29, 2006)
|
||||||
|
|
||||||
|
The first release.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.02 (June 01, 2006)
|
||||||
|
|
||||||
|
Added FAT12 support.
|
||||||
|
Removed unbuffered mode.
|
||||||
|
Fixed a problem on small (<32M) partition.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.02a (June 10, 2006)
|
||||||
|
|
||||||
|
Added a configuration option (_FS_MINIMUM).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.03 (September 22, 2006)
|
||||||
|
|
||||||
|
Added f_rename().
|
||||||
|
Changed option _FS_MINIMUM to _FS_MINIMIZE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.03a (December 11, 2006)
|
||||||
|
|
||||||
|
Improved cluster scan algorithm to write files fast.
|
||||||
|
Fixed f_mkdir() creates incorrect directory on FAT32.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.04 (February 04, 2007)
|
||||||
|
|
||||||
|
Added f_mkfs().
|
||||||
|
Supported multiple drive system.
|
||||||
|
Changed some interfaces for multiple drive system.
|
||||||
|
Changed f_mountdrv() to f_mount().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.04a (April 01, 2007)
|
||||||
|
|
||||||
|
Supported multiple partitions on a physical drive.
|
||||||
|
Added a capability of extending file size to f_lseek().
|
||||||
|
Added minimization level 3.
|
||||||
|
Fixed an endian sensitive code in f_mkfs().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.04b (May 05, 2007)
|
||||||
|
|
||||||
|
Added a configuration option _USE_NTFLAG.
|
||||||
|
Added FSINFO support.
|
||||||
|
Fixed DBCS name can result FR_INVALID_NAME.
|
||||||
|
Fixed short seek (<= csize) collapses the file object.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.05 (August 25, 2007)
|
||||||
|
|
||||||
|
Changed arguments of f_read(), f_write() and f_mkfs().
|
||||||
|
Fixed f_mkfs() on FAT32 creates incorrect FSINFO.
|
||||||
|
Fixed f_mkdir() on FAT32 creates incorrect directory.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.05a (February 03, 2008)
|
||||||
|
|
||||||
|
Added f_truncate() and f_utime().
|
||||||
|
Fixed off by one error at FAT sub-type determination.
|
||||||
|
Fixed btr in f_read() can be mistruncated.
|
||||||
|
Fixed cached sector is not flushed when create and close without write.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.06 (April 01, 2008)
|
||||||
|
|
||||||
|
Added fputc(), fputs(), fprintf() and fgets().
|
||||||
|
Improved performance of f_lseek() on moving to the same or following cluster.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.07 (April 01, 2009)
|
||||||
|
|
||||||
|
Merged Tiny-FatFs as a configuration option. (_FS_TINY)
|
||||||
|
Added long file name feature. (_USE_LFN)
|
||||||
|
Added multiple code page feature. (_CODE_PAGE)
|
||||||
|
Added re-entrancy for multitask operation. (_FS_REENTRANT)
|
||||||
|
Added auto cluster size selection to f_mkfs().
|
||||||
|
Added rewind option to f_readdir().
|
||||||
|
Changed result code of critical errors.
|
||||||
|
Renamed string functions to avoid name collision.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.07a (April 14, 2009)
|
||||||
|
|
||||||
|
Septemberarated out OS dependent code on reentrant cfg.
|
||||||
|
Added multiple sector size feature.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.07c (June 21, 2009)
|
||||||
|
|
||||||
|
Fixed f_unlink() can return FR_OK on error.
|
||||||
|
Fixed wrong cache control in f_lseek().
|
||||||
|
Added relative path feature.
|
||||||
|
Added f_chdir() and f_chdrive().
|
||||||
|
Added proper case conversion to extended character.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.07e (November 03, 2009)
|
||||||
|
|
||||||
|
Septemberarated out configuration options from ff.h to ffconf.h.
|
||||||
|
Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
|
||||||
|
Fixed name matching error on the 13 character boundary.
|
||||||
|
Added a configuration option, _LFN_UNICODE.
|
||||||
|
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.08 (May 15, 2010)
|
||||||
|
|
||||||
|
Added a memory configuration option. (_USE_LFN = 3)
|
||||||
|
Added file lock feature. (_FS_SHARE)
|
||||||
|
Added fast seek feature. (_USE_FASTSEEK)
|
||||||
|
Changed some types on the API, XCHAR->TCHAR.
|
||||||
|
Changed .fname in the FILINFO structure on Unicode cfg.
|
||||||
|
String functions support UTF-8 encoding files on Unicode cfg.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.08a (August 16, 2010)
|
||||||
|
|
||||||
|
Added f_getcwd(). (_FS_RPATH = 2)
|
||||||
|
Added sector erase feature. (_USE_ERASE)
|
||||||
|
Moved file lock semaphore table from fs object to the bss.
|
||||||
|
Fixed f_mkfs() creates wrong FAT32 volume.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.08b (January 15, 2011)
|
||||||
|
|
||||||
|
Fast seek feature is also applied to f_read() and f_write().
|
||||||
|
f_lseek() reports required table size on creating CLMP.
|
||||||
|
Extended format syntax of f_printf().
|
||||||
|
Ignores duplicated directory separators in given path name.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.09 (September 06, 2011)
|
||||||
|
|
||||||
|
f_mkfs() supports multiple partition to complete the multiple partition feature.
|
||||||
|
Added f_fdisk().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.09a (August 27, 2012)
|
||||||
|
|
||||||
|
Changed f_open() and f_opendir() reject null object pointer to avoid crash.
|
||||||
|
Changed option name _FS_SHARE to _FS_LOCK.
|
||||||
|
Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.09b (January 24, 2013)
|
||||||
|
|
||||||
|
Added f_setlabel() and f_getlabel().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.10 (October 02, 2013)
|
||||||
|
|
||||||
|
Added selection of character encoding on the file. (_STRF_ENCODE)
|
||||||
|
Added f_closedir().
|
||||||
|
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
|
||||||
|
Added forced mount feature with changes of f_mount().
|
||||||
|
Improved behavior of volume auto detection.
|
||||||
|
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 value on error.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.10a (January 15, 2014)
|
||||||
|
|
||||||
|
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
|
||||||
|
Added a configuration option of minimum sector size. (_MIN_SS)
|
||||||
|
2nd argument of f_rename() can have a drive number and it will be ignored.
|
||||||
|
Fixed f_mount() with forced mount fails when drive number is >= 1. (appeared at R0.10)
|
||||||
|
Fixed f_close() invalidates the file object without volume lock.
|
||||||
|
Fixed f_closedir() returns but the volume lock is left acquired. (appeared at R0.10)
|
||||||
|
Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 when delete/rename an object with lossy converted SFN. (appeared at R0.07)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.10c (November 09, 2014)
|
||||||
|
|
||||||
|
Added a configuration option for the platforms without RTC. (_FS_NORTC)
|
||||||
|
Changed option name _USE_ERASE to _USE_TRIM.
|
||||||
|
Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b)
|
||||||
|
Fixed a potential problem of FAT access that can appear on disk error.
|
||||||
|
Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.11 (February 09, 2015)
|
||||||
|
|
||||||
|
Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND)
|
||||||
|
Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c)
|
||||||
|
Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.11a (September 05, 2015)
|
||||||
|
|
||||||
|
Fixed wrong media change can lead a deadlock at thread-safe configuration.
|
||||||
|
Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
|
||||||
|
Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
|
||||||
|
Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.14 (October 14, 2019)
|
||||||
|
Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1)
|
||||||
|
Changed some API functions, f_mkfs() and f_fdisk().
|
||||||
|
Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters.
|
||||||
|
Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters.
|
||||||
|
Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12)
|
||||||
|
Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12)
|
||||||
|
|
||||||
|
|
||||||
|
R0.14a (December 5, 2020)
|
||||||
|
Limited number of recursive calls in f_findnext().
|
||||||
|
Fixed old floppy disks formatted with MS-DOS 2.x and 3.x cannot be mounted.
|
||||||
|
Fixed some compiler warnings.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.14b (April 17, 2021)
|
||||||
|
Made FatFs uses standard library <string.h> for copy, compare and search instead of built-in string functions.
|
||||||
|
Added support for long long integer and floating point to f_printf(). (FF_STRF_LLI and FF_STRF_FP)
|
||||||
|
Made path name parser ignore the terminating separator to allow "dir/".
|
||||||
|
Improved the compatibility in Unix style path name feature.
|
||||||
|
Fixed the file gets dead-locked when f_open() failed with some conditions. (appeared at R0.12a)
|
||||||
|
Fixed f_mkfs() can create wrong exFAT volume due to a timing dependent error. (appeared at R0.12)
|
||||||
|
Fixed code page 855 cannot be set by f_setcp().
|
||||||
|
Fixed some compiler warnings.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
R0.15 (November 6, 2022)
|
||||||
|
Changed user provided synchronization functions in order to completely eliminate the platform dependency from FatFs code.
|
||||||
|
FF_SYNC_t is removed from the configuration options.
|
||||||
|
Fixed a potential error in f_mount when FF_FS_REENTRANT.
|
||||||
|
Fixed file lock control FF_FS_LOCK is not mutal excluded when FF_FS_REENTRANT && FF_VOLUMES > 1 is true.
|
||||||
|
Fixed f_mkfs() creates broken exFAT volume when the size of volume is >= 2^32 sectors.
|
||||||
|
Fixed string functions cannot write the unicode characters not in BMP when FF_LFN_UNICODE == 2 (UTF-8).
|
||||||
|
Fixed a compatibility issue in identification of GPT header.
|
||||||
|
|
||||||
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.15
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
186
arm9/source/fatfs/diskio.c
Normal file
186
arm9/source/fatfs/diskio.c
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* 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 "ff.h" /* Obtains integer types */
|
||||||
|
#include "diskio.h" /* Declarations of disk functions */
|
||||||
|
#include "sdmmc/sdmmc.h"
|
||||||
|
#include "../crypto.h"
|
||||||
|
#include "../i2c.h"
|
||||||
|
|
||||||
|
/* Definitions of physical drive number for each drive */
|
||||||
|
#define SDCARD 0
|
||||||
|
#define CTRNAND 1
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Get Drive Status */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DSTATUS disk_status (
|
||||||
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
(void)pdrv;
|
||||||
|
return RES_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Inidialize a Drive */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DSTATUS disk_initialize (
|
||||||
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static u32 sdmmcInitResult = 4;
|
||||||
|
DSTATUS res = 0;
|
||||||
|
|
||||||
|
if(sdmmcInitResult == 4)
|
||||||
|
sdmmcInitResult = sdmmc_sdcard_init();
|
||||||
|
|
||||||
|
// Check physical drive initialized status
|
||||||
|
switch (pdrv)
|
||||||
|
{
|
||||||
|
case SDCARD:
|
||||||
|
res = (sdmmcInitResult & 2) == 0 ? 0 : STA_NOINIT;
|
||||||
|
break;
|
||||||
|
case CTRNAND:
|
||||||
|
// Always update CTRNAND parameters when remounting
|
||||||
|
res = (sdmmcInitResult & 1) == 0 && ctrNandInit() == 0 ? 0 : STA_NOINIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = STA_NODISK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Read Sector(s) */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DRESULT disk_read (
|
||||||
|
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||||
|
BYTE *buff, /* Data buffer to store read data */
|
||||||
|
LBA_t sector, /* Start sector in LBA */
|
||||||
|
UINT count /* Number of sectors to read */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DRESULT res = RES_OK;
|
||||||
|
|
||||||
|
switch (pdrv)
|
||||||
|
{
|
||||||
|
case SDCARD:
|
||||||
|
res = sdmmc_sdcard_readsectors(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
||||||
|
break;
|
||||||
|
case CTRNAND:
|
||||||
|
res = ctrNandRead(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = RES_NOTRDY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Write Sector(s) */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if FF_FS_READONLY == 0
|
||||||
|
|
||||||
|
DRESULT disk_write (
|
||||||
|
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||||
|
const BYTE *buff, /* Data to be written */
|
||||||
|
LBA_t sector, /* Start sector in LBA */
|
||||||
|
UINT count /* Number of sectors to write */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DRESULT res = RES_OK;
|
||||||
|
|
||||||
|
switch (pdrv)
|
||||||
|
{
|
||||||
|
case SDCARD:
|
||||||
|
{
|
||||||
|
if ((*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) // why == 0?
|
||||||
|
res = RES_WRPRT;
|
||||||
|
else
|
||||||
|
res = sdmmc_sdcard_writesectors(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CTRNAND:
|
||||||
|
res = ctrNandWrite(sector, count, buff) == 0 ? RES_OK : RES_PARERR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = RES_NOTRDY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Miscellaneous Functions */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DRESULT disk_ioctl (
|
||||||
|
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||||
|
BYTE cmd, /* Control code */
|
||||||
|
void *buff /* Buffer to send/receive control data */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
(void)pdrv;
|
||||||
|
(void)buff;
|
||||||
|
return cmd == CTRL_SYNC ? RES_OK : RES_PARERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*-----------------------------------------------------------------------/
|
/*-----------------------------------------------------------------------/
|
||||||
/ Low level disk interface modlue include file (C)ChaN, 2014 /
|
/ Low level disk interface modlue include file (C)ChaN, 2019 /
|
||||||
/-----------------------------------------------------------------------*/
|
/-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef _DISKIO_DEFINED
|
#ifndef _DISKIO_DEFINED
|
||||||
@ -9,12 +9,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _USE_WRITE 1 /* 1: Enable disk_write function */
|
|
||||||
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
|
|
||||||
|
|
||||||
#include "integer.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Status of Disk Functions */
|
/* Status of Disk Functions */
|
||||||
typedef BYTE DSTATUS;
|
typedef BYTE DSTATUS;
|
||||||
|
|
||||||
@ -34,8 +28,8 @@ typedef enum {
|
|||||||
|
|
||||||
DSTATUS disk_initialize (BYTE pdrv);
|
DSTATUS disk_initialize (BYTE pdrv);
|
||||||
DSTATUS disk_status (BYTE pdrv);
|
DSTATUS disk_status (BYTE pdrv);
|
||||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
|
||||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
|
||||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||||
|
|
||||||
|
|
||||||
@ -49,11 +43,11 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
|||||||
/* Command code for disk_ioctrl fucntion */
|
/* Command code for disk_ioctrl fucntion */
|
||||||
|
|
||||||
/* Generic command (Used by FatFs) */
|
/* Generic command (Used by FatFs) */
|
||||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
|
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
|
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
|
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
|
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
|
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||||
|
|
||||||
/* Generic command (Not used by FatFs) */
|
/* Generic command (Not used by FatFs) */
|
||||||
#define CTRL_POWER 5 /* Get/Set power status */
|
#define CTRL_POWER 5 /* Get/Set power status */
|
||||||
@ -67,6 +61,9 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
|||||||
#define MMC_GET_CID 12 /* Get CID */
|
#define MMC_GET_CID 12 /* Get CID */
|
||||||
#define MMC_GET_OCR 13 /* Get OCR */
|
#define MMC_GET_OCR 13 /* Get OCR */
|
||||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||||
|
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
|
||||||
|
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
|
||||||
|
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
|
||||||
|
|
||||||
/* ATA/CF specific ioctl command */
|
/* ATA/CF specific ioctl command */
|
||||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||||
7084
arm9/source/fatfs/ff.c
Normal file
7084
arm9/source/fatfs/ff.c
Normal file
File diff suppressed because it is too large
Load Diff
429
arm9/source/fatfs/ff.h
Normal file
429
arm9/source/fatfs/ff.h
Normal file
@ -0,0 +1,429 @@
|
|||||||
|
/*----------------------------------------------------------------------------/
|
||||||
|
/ FatFs - Generic FAT Filesystem module R0.15 /
|
||||||
|
/-----------------------------------------------------------------------------/
|
||||||
|
/
|
||||||
|
/ Copyright (C) 2022, 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 80286 /* 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) /* Windows VC++ (for development only) */
|
||||||
|
#define FF_INTDEF 2
|
||||||
|
#include <windows.h>
|
||||||
|
typedef unsigned __int64 QWORD;
|
||||||
|
#include <float.h>
|
||||||
|
#define isnan(v) _isnan(v)
|
||||||
|
#define isinf(v) (!_finite(v))
|
||||||
|
|
||||||
|
#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 uint32_t DWORD; /* 32-bit unsigned integer */
|
||||||
|
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||||
|
typedef WORD WCHAR; /* UTF-16 character type */
|
||||||
|
|
||||||
|
#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 long DWORD; /* 32-bit unsigned integer */
|
||||||
|
typedef WORD WCHAR; /* UTF-16 character type */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Type of file size and LBA variables */
|
||||||
|
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
#if FF_INTDEF != 2
|
||||||
|
#error exFAT feature wants C99 or later
|
||||||
|
#endif
|
||||||
|
typedef QWORD FSIZE_t;
|
||||||
|
#if FF_LBA64
|
||||||
|
typedef QWORD LBA_t;
|
||||||
|
#else
|
||||||
|
typedef DWORD LBA_t;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if FF_LBA64
|
||||||
|
#error exFAT needs to be enabled when enable 64-bit LBA
|
||||||
|
#endif
|
||||||
|
typedef DWORD FSIZE_t;
|
||||||
|
typedef DWORD LBA_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Type of path name strings on FatFs API (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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 mapping table */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if FF_STR_VOLUME_ID
|
||||||
|
#ifndef FF_VOLUME_STRS
|
||||||
|
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Filesystem object structure (FATFS) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||||
|
BYTE pdrv; /* Volume hosting physical drive */
|
||||||
|
BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */
|
||||||
|
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||||
|
BYTE wflag; /* win[] status (b0:dirty) */
|
||||||
|
BYTE fsi_flag; /* FSINFO status (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_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; /* Number of sectors per FAT */
|
||||||
|
LBA_t volbase; /* Volume base sector */
|
||||||
|
LBA_t fatbase; /* FAT base sector */
|
||||||
|
LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */
|
||||||
|
LBA_t database; /* Data base sector */
|
||||||
|
#if FF_FS_EXFAT
|
||||||
|
LBA_t bitbase; /* Allocation bitmap base sector */
|
||||||
|
#endif
|
||||||
|
LBA_t 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's 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) */
|
||||||
|
LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||||
|
#if !FF_FS_READONLY
|
||||||
|
LBA_t 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 */
|
||||||
|
LBA_t 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];/* Alternative file name */
|
||||||
|
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||||
|
#else
|
||||||
|
TCHAR fname[12 + 1]; /* File name */
|
||||||
|
#endif
|
||||||
|
} FILINFO;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Format parameter structure (MKFS_PARM) */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
|
||||||
|
BYTE n_fat; /* Number of FATs */
|
||||||
|
UINT align; /* Data area alignment (sector) */
|
||||||
|
UINT n_root; /* Number of root directory entries */
|
||||||
|
DWORD au_size; /* Cluster size (byte) */
|
||||||
|
} MKFS_PARM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* 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 fsz, 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, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
|
||||||
|
FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], 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 */
|
||||||
|
|
||||||
|
/* Some API fucntions are implemented as macro */
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
/* Additional Functions */
|
||||||
|
/*--------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* RTC function (provided by user) */
|
||||||
|
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||||
|
DWORD get_fattime (void); /* Get current time */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* LFN support functions (defined in ffunicode.c) */
|
||||||
|
|
||||||
|
#if FF_USE_LFN >= 1
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
/* O/S dependent functions (samples available in ffsystem.c) */
|
||||||
|
|
||||||
|
#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
|
||||||
|
#if FF_FS_REENTRANT /* Sync functions */
|
||||||
|
int ff_mutex_create (int vol); /* Create a sync object */
|
||||||
|
void ff_mutex_delete (int vol); /* Delete a sync object */
|
||||||
|
int ff_mutex_take (int vol); /* Lock sync object */
|
||||||
|
void ff_mutex_give (int vol); /* Unlock 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 */
|
||||||
296
arm9/source/fatfs/ffconf.h
Normal file
296
arm9/source/fatfs/ffconf.h
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ Configurations of FatFs Module
|
||||||
|
/---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define FFCONF_DEF 80286 /* 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_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) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_USE_STRFUNC 0
|
||||||
|
#define FF_PRINT_LLI 1
|
||||||
|
#define FF_PRINT_FLOAT 1
|
||||||
|
#define FF_STRF_ENCODE 3
|
||||||
|
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
|
||||||
|
/ f_printf().
|
||||||
|
/
|
||||||
|
/ 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
|
||||||
|
/ 1: Enable without LF-CRLF conversion.
|
||||||
|
/ 2: Enable with LF-CRLF conversion.
|
||||||
|
/
|
||||||
|
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
|
||||||
|
/ makes f_printf() support floating point argument. These features want C99 or later.
|
||||||
|
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
|
||||||
|
/ encoding in it. FF_STRF_ENCODE 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ 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 it 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() exemplified 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_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 1
|
||||||
|
#define FF_VOLUME_STRS "sdmc", "nand"
|
||||||
|
/* 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 is needed 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()
|
||||||
|
/ function 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_LBA64 0
|
||||||
|
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
|
||||||
|
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_MIN_GPT 0x10000000
|
||||||
|
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
|
||||||
|
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
|
||||||
|
|
||||||
|
|
||||||
|
#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. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------/
|
||||||
|
/ 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 2022
|
||||||
|
/* The option FF_FS_NORTC switches timestamp feature. If the system does not have
|
||||||
|
/ an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the
|
||||||
|
/ timestamp feature. 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 in read-only configuration (FF_FS_READONLY = 1). */
|
||||||
|
|
||||||
|
|
||||||
|
#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 the 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#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. */
|
||||||
|
|
||||||
|
|
||||||
|
#define FF_FS_REENTRANT 0
|
||||||
|
#define FF_FS_TIMEOUT 1000
|
||||||
|
/* 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 featuer.
|
||||||
|
/
|
||||||
|
/ 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect.
|
||||||
|
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||||
|
/ ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give()
|
||||||
|
/ function, must be added to the project. Samples are available in ffsystem.c.
|
||||||
|
/
|
||||||
|
/ The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--- End of configuration options ---*/
|
||||||
208
arm9/source/fatfs/ffsystem.c
Normal file
208
arm9/source/fatfs/ffsystem.c
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* A Sample Code of User Provided OS Dependent Functions for FatFs */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "ff.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if FF_USE_LFN == 3 /* Use dynamic memory allocation */
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Allocate/Free a Memory Block */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <stdlib.h> /* with POSIX API */
|
||||||
|
|
||||||
|
|
||||||
|
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
|
||||||
|
UINT msize /* Number of bytes to allocate */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return malloc((size_t)msize); /* Allocate a new memory block */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ff_memfree (
|
||||||
|
void* mblock /* Pointer to the memory block to free (no effect if null) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
free(mblock); /* Free the memory block */
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Definitions of Mutex */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define OS_TYPE 0 /* 0:Win32, 1:uITRON4.0, 2:uC/OS-II, 3:FreeRTOS, 4:CMSIS-RTOS */
|
||||||
|
|
||||||
|
|
||||||
|
#if OS_TYPE == 0 /* Win32 */
|
||||||
|
#include <windows.h>
|
||||||
|
static HANDLE Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
|
||||||
|
|
||||||
|
#elif OS_TYPE == 1 /* uITRON */
|
||||||
|
#include "itron.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
static mtxid Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
|
||||||
|
|
||||||
|
#elif OS_TYPE == 2 /* uc/OS-II */
|
||||||
|
#include "includes.h"
|
||||||
|
static OS_EVENT *Mutex[FF_VOLUMES + 1]; /* Table of mutex pinter */
|
||||||
|
|
||||||
|
#elif OS_TYPE == 3 /* FreeRTOS */
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "semphr.h"
|
||||||
|
static SemaphoreHandle_t Mutex[FF_VOLUMES + 1]; /* Table of mutex handle */
|
||||||
|
|
||||||
|
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
static osMutexId Mutex[FF_VOLUMES + 1]; /* Table of mutex ID */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Create a Mutex */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* This function is called in f_mount function to create a new mutex
|
||||||
|
/ or semaphore for the volume. When a 0 is returned, the f_mount function
|
||||||
|
/ fails with FR_INT_ERR.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */
|
||||||
|
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if OS_TYPE == 0 /* Win32 */
|
||||||
|
Mutex[vol] = CreateMutex(NULL, FALSE, NULL);
|
||||||
|
return (int)(Mutex[vol] != INVALID_HANDLE_VALUE);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 1 /* uITRON */
|
||||||
|
T_CMTX cmtx = {TA_TPRI,1};
|
||||||
|
|
||||||
|
Mutex[vol] = acre_mtx(&cmtx);
|
||||||
|
return (int)(Mutex[vol] > 0);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 2 /* uC/OS-II */
|
||||||
|
OS_ERR err;
|
||||||
|
|
||||||
|
Mutex[vol] = OSMutexCreate(0, &err);
|
||||||
|
return (int)(err == OS_NO_ERR);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 3 /* FreeRTOS */
|
||||||
|
Mutex[vol] = xSemaphoreCreateMutex();
|
||||||
|
return (int)(Mutex[vol] != NULL);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
||||||
|
osMutexDef(cmsis_os_mutex);
|
||||||
|
|
||||||
|
Mutex[vol] = osMutexCreate(osMutex(cmsis_os_mutex));
|
||||||
|
return (int)(Mutex[vol] != NULL);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Delete a Mutex */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* This function is called in f_mount function to delete a mutex or
|
||||||
|
/ semaphore of the volume created with ff_mutex_create function.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */
|
||||||
|
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if OS_TYPE == 0 /* Win32 */
|
||||||
|
CloseHandle(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 1 /* uITRON */
|
||||||
|
del_mtx(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 2 /* uC/OS-II */
|
||||||
|
OS_ERR err;
|
||||||
|
|
||||||
|
OSMutexDel(Mutex[vol], OS_DEL_ALWAYS, &err);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 3 /* FreeRTOS */
|
||||||
|
vSemaphoreDelete(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
||||||
|
osMutexDelete(Mutex[vol]);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Request a Grant to Access the Volume */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* This function is called on enter file functions to lock the volume.
|
||||||
|
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */
|
||||||
|
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if OS_TYPE == 0 /* Win32 */
|
||||||
|
return (int)(WaitForSingleObject(Mutex[vol], FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 1 /* uITRON */
|
||||||
|
return (int)(tloc_mtx(Mutex[vol], FF_FS_TIMEOUT) == E_OK);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 2 /* uC/OS-II */
|
||||||
|
OS_ERR err;
|
||||||
|
|
||||||
|
OSMutexPend(Mutex[vol], FF_FS_TIMEOUT, &err));
|
||||||
|
return (int)(err == OS_NO_ERR);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 3 /* FreeRTOS */
|
||||||
|
return (int)(xSemaphoreTake(Mutex[vol], FF_FS_TIMEOUT) == pdTRUE);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
||||||
|
return (int)(osMutexWait(Mutex[vol], FF_FS_TIMEOUT) == osOK);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* Release a Grant to Access the Volume */
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
/* This function is called on leave file functions to unlock the volume.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ff_mutex_give (
|
||||||
|
int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if OS_TYPE == 0 /* Win32 */
|
||||||
|
ReleaseMutex(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 1 /* uITRON */
|
||||||
|
unl_mtx(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 2 /* uC/OS-II */
|
||||||
|
OSMutexPost(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 3 /* FreeRTOS */
|
||||||
|
xSemaphoreGive(Mutex[vol]);
|
||||||
|
|
||||||
|
#elif OS_TYPE == 4 /* CMSIS-RTOS */
|
||||||
|
osMutexRelease(Mutex[vol]);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FF_FS_REENTRANT */
|
||||||
|
|
||||||
15593
arm9/source/fatfs/ffunicode.c
Normal file
15593
arm9/source/fatfs/ffunicode.c
Normal file
File diff suppressed because it is too large
Load Diff
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);
|
||||||
803
arm9/source/firm.c
Executable file
803
arm9/source/firm.c
Executable file
@ -0,0 +1,803 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2021 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;
|
||||||
|
u32 firmProtoVersion = 0;
|
||||||
|
|
||||||
|
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 = 0xFFFFFFFF,
|
||||||
|
firmSize;
|
||||||
|
|
||||||
|
bool ctrNandError = true;
|
||||||
|
bool loadedFromStorage = false;
|
||||||
|
bool storageLoadError = false;
|
||||||
|
|
||||||
|
// Try loading FIRM from sdmc first if specified.
|
||||||
|
if (loadFromStorage) {
|
||||||
|
firmSize = loadFirmFromStorage(*firmType);
|
||||||
|
if (firmSize != 0) loadedFromStorage = true;
|
||||||
|
else storageLoadError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remount ctrnand and load FIRM from it if loading from sdmc failed.
|
||||||
|
if (!loadedFromStorage) {
|
||||||
|
ctrNandError = isSdMode && !remountCtrNandPartition(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If CTRNAND load failed, and it wasn't tried yet, load FIRM from sdmc.
|
||||||
|
if (ctrNandError && !storageLoadError)
|
||||||
|
{
|
||||||
|
u32 result = loadFirmFromStorage(*firmType);
|
||||||
|
|
||||||
|
if(result != 0)
|
||||||
|
{
|
||||||
|
loadedFromStorage = true;
|
||||||
|
firmSize = result;
|
||||||
|
}
|
||||||
|
else storageLoadError = true;
|
||||||
|
}
|
||||||
|
// If all attempts failed, panic.
|
||||||
|
if(ctrNandError && storageLoadError) 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
|
||||||
|
bool isO3dsFirm = firm->section[3].offset == 0 && firm->section[2].address == (u8 *)0x8006800;
|
||||||
|
|
||||||
|
if(loadedFromStorage || ISDEVUNIT)
|
||||||
|
{
|
||||||
|
firmVersion = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
if(isO3dsFirm && (*firmType == NATIVE_FIRM || *firmType == NATIVE_FIRM1X2X))
|
||||||
|
{
|
||||||
|
__attribute__((aligned(4))) static const u8 hashes[5][0x20] = {
|
||||||
|
{0xD7, 0x43, 0x0F, 0x27, 0x8D, 0xC9, 0x3F, 0x4C, 0x96, 0xB5, 0xA8, 0x91, 0x48, 0xDB, 0x08, 0x8A,
|
||||||
|
0x7E, 0x46, 0xB3, 0x95, 0x65, 0xA2, 0x05, 0xF1, 0xF2, 0x41, 0x21, 0xF1, 0x0C, 0x59, 0x6A, 0x9D},
|
||||||
|
{0x93, 0xDF, 0x49, 0xA1, 0x24, 0x86, 0xBB, 0x6F, 0xAF, 0x49, 0x99, 0x2D, 0xD0, 0x8D, 0xB1, 0x88,
|
||||||
|
0x8A, 0x00, 0xB6, 0xDD, 0x36, 0x89, 0xC0, 0xE2, 0xC9, 0xA9, 0x99, 0x62, 0x57, 0x5E, 0x6C, 0x23},
|
||||||
|
{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 < sizeof(hashes)/sizeof(hashes[0]); i++)
|
||||||
|
{
|
||||||
|
if(memcmp(firm->section[1].hash, hashes[i], 0x20) == 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(i)
|
||||||
|
{
|
||||||
|
// Beta
|
||||||
|
case 0:
|
||||||
|
firmVersion = 0x0;
|
||||||
|
firmProtoVersion = 243;
|
||||||
|
*firmType = NATIVE_PROTOTYPE;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
firmVersion = 0x0;
|
||||||
|
firmProtoVersion = 238;
|
||||||
|
*firmType = NATIVE_PROTOTYPE;
|
||||||
|
break;
|
||||||
|
// Release
|
||||||
|
case 2:
|
||||||
|
firmVersion = 0x18;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
firmVersion = 0x1D;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
firmVersion = 0x1F;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*firmType != NATIVE_PROTOTYPE && (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 you want to use SAFE_FIRM on 1.0, use Luma from NAND & comment this line:
|
||||||
|
if(isSafeMode) error("SAFE_MODE is not supported on 1.x/2.x FIRM.");
|
||||||
|
|
||||||
|
*firmType = NATIVE_FIRM1X2X;
|
||||||
|
}
|
||||||
|
|
||||||
|
return firmVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadHomebrewFirm(u32 pressed)
|
||||||
|
{
|
||||||
|
char path[10 + 255];
|
||||||
|
bool hasDisplayedMenu = false;
|
||||||
|
bool found = !pressed ? payloadMenu(path, &hasDisplayedMenu) : 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};
|
||||||
|
bool wantsScreenInit = (firm->reserved2[0] & 1) != 0;
|
||||||
|
|
||||||
|
if(!hasDisplayedMenu && wantsScreenInit)
|
||||||
|
initScreens(); // Don't init the screens unless we have to, if not already done
|
||||||
|
|
||||||
|
launchFirm(wantsScreenInit ? 2 : 1, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct CopyKipResult {
|
||||||
|
u32 cxiSize;
|
||||||
|
u8 *codeDstAddr;
|
||||||
|
u32 codeSize;
|
||||||
|
} CopyKipResult;
|
||||||
|
|
||||||
|
// Copy a KIP, decompressing it in place if necessary (TwlBg)
|
||||||
|
static CopyKipResult copyKip(u8 *dst, const u8 *src, u32 maxSize, bool decompress)
|
||||||
|
{
|
||||||
|
const char *extModuleSizeError = "The external FIRM modules are too large.";
|
||||||
|
CopyKipResult res = { 0 };
|
||||||
|
Cxi *dstCxi = (Cxi *)dst;
|
||||||
|
const Cxi *srcCxi = (const Cxi *)src;
|
||||||
|
|
||||||
|
u32 mediaUnitShift = 9 + srcCxi->ncch.flags[6];
|
||||||
|
u32 totalSizeCompressed = srcCxi->ncch.contentSize << mediaUnitShift;
|
||||||
|
|
||||||
|
if (totalSizeCompressed > maxSize)
|
||||||
|
error(extModuleSizeError);
|
||||||
|
|
||||||
|
// First, copy the compressed KIP to the destination
|
||||||
|
memcpy(dst, src, totalSizeCompressed);
|
||||||
|
|
||||||
|
ExHeader *exh = &dstCxi->exHeader;
|
||||||
|
bool isCompressed = (exh->systemControlInfo.flag & 1) != 0;
|
||||||
|
ExeFsHeader *exefs = (ExeFsHeader *)(dst + (dstCxi->ncch.exeFsOffset << mediaUnitShift));
|
||||||
|
ExeFsFileHeader *fh = &exefs->fileHeaders[0];
|
||||||
|
u8 *codeAddr = (u8 *)exefs + sizeof(ExeFsHeader) + fh->offset;
|
||||||
|
|
||||||
|
if (memcmp(fh->name, ".code\0\0\0", 8) != 0 || fh->offset != 0 || exefs->fileHeaders[1].size != 0)
|
||||||
|
error("One of the external FIRM modules have invalid layout.");
|
||||||
|
|
||||||
|
// If it's already decompressed or we don't need to, there is not much left to do
|
||||||
|
if (!decompress || !isCompressed)
|
||||||
|
{
|
||||||
|
res.cxiSize = totalSizeCompressed;
|
||||||
|
res.codeDstAddr = codeAddr;
|
||||||
|
res.codeSize = fh->size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u32 codeSize = exh->systemControlInfo.textCodeSet.size;
|
||||||
|
codeSize += exh->systemControlInfo.roCodeSet.size;
|
||||||
|
codeSize += exh->systemControlInfo.dataCodeSet.size;
|
||||||
|
|
||||||
|
u32 codeSizePadded = ((codeSize + (1 << mediaUnitShift) - 1) >> mediaUnitShift) << mediaUnitShift;
|
||||||
|
u32 newTotalSize = (codeAddr + codeSizePadded) - dst;
|
||||||
|
if (newTotalSize > maxSize)
|
||||||
|
error(extModuleSizeError);
|
||||||
|
|
||||||
|
// Decompress in place
|
||||||
|
lzss_decompress(codeAddr + fh->size);
|
||||||
|
|
||||||
|
// Fill padding just in case
|
||||||
|
memset(codeAddr + codeSize, 0, codeSizePadded - codeSize);
|
||||||
|
|
||||||
|
// Fix fields
|
||||||
|
fh->size = codeSize;
|
||||||
|
dstCxi->ncch.exeFsSize = codeSizePadded >> mediaUnitShift;
|
||||||
|
exh->systemControlInfo.flag &= ~1;
|
||||||
|
dstCxi->ncch.contentSize = newTotalSize >> mediaUnitShift;
|
||||||
|
|
||||||
|
res.cxiSize = newTotalSize;
|
||||||
|
res.codeDstAddr = codeAddr;
|
||||||
|
res.codeSize = codeSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
static void mergeSection0(FirmwareType firmType, u32 firmVersion, bool loadFromStorage)
|
||||||
|
{
|
||||||
|
u32 srcModuleSize,
|
||||||
|
nbModules = 0;
|
||||||
|
|
||||||
|
bool isLgyFirm = firmType == TWL_FIRM || firmType == AGB_FIRM;
|
||||||
|
|
||||||
|
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 >= 0x25))
|
||||||
|
{
|
||||||
|
//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 = !isLgyFirm ? 0x80000 : 0x600000;
|
||||||
|
u32 dstModuleSize = 0;
|
||||||
|
for(u32 i = 0; i < nbModules; i++)
|
||||||
|
{
|
||||||
|
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.");
|
||||||
|
|
||||||
|
dst += dstModuleSize;
|
||||||
|
maxModuleSize -= dstModuleSize;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not successfully loaded from storage, then...
|
||||||
|
|
||||||
|
// Decompress stock TwlBg so that we can patch it
|
||||||
|
bool isStockTwlBg = firmType == TWL_FIRM && strcmp(moduleList[i].name, "TwlBg") == 0;
|
||||||
|
|
||||||
|
CopyKipResult copyRes = copyKip(dst, moduleList[i].src, maxModuleSize, isStockTwlBg);
|
||||||
|
|
||||||
|
if (isStockTwlBg)
|
||||||
|
patchTwlBg(copyRes.codeDstAddr, copyRes.codeSize);
|
||||||
|
|
||||||
|
dst += copyRes.cxiSize;
|
||||||
|
maxModuleSize -= copyRes.cxiSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//4) Patch kernel to take module size into account
|
||||||
|
u32 newKipSectionSize = dst - firm->section[0].address;
|
||||||
|
u32 oldKipSectionSize = firm->section[0].size;
|
||||||
|
u8 *kernel11Addr = (u8 *)firm + firm->section[1].offset;
|
||||||
|
u32 kernel11Size = firm->section[1].size;
|
||||||
|
if (isLgyFirm)
|
||||||
|
{
|
||||||
|
if (patchK11ModuleLoadingLgy(newKipSectionSize, kernel11Addr, kernel11Size) != 0)
|
||||||
|
error("Failed to load sysmodules");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (patchK11ModuleLoading(oldKipSectionSize, newKipSectionSize, nbModules, kernel11Addr, kernel11Size) != 0)
|
||||||
|
error("Failed to load sysmodules");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool needToInitSd, bool doUnitinfoPatch)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
#ifndef BUILD_FOR_EXPLOIT_DEV
|
||||||
|
//Skip on FIRMs < 5.0
|
||||||
|
if(ISN3DS || firmVersion >= 0x25)
|
||||||
|
{
|
||||||
|
//Find the Kernel11 SVC table and handler, exceptions page and free space locations
|
||||||
|
u8 *arm11Section1 = (u8 *)firm + firm->section[1].offset;
|
||||||
|
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, needToInitSd, baseK11VA, arm11ExceptionsPage, &freeK11Space);
|
||||||
|
ret += patchKernel11(arm11Section1, firm->section[1].size, baseK11VA, arm11SvcTable, arm11ExceptionsPage);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)needToInitSd;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//Apply signature patches
|
||||||
|
ret += patchSignatureChecks(process9Offset, process9Size);
|
||||||
|
|
||||||
|
//Apply EmuNAND patches
|
||||||
|
if(nandType != FIRMWARE_SYSNAND) ret += patchEmuNand(process9Offset, process9Size, firmVersion);
|
||||||
|
|
||||||
|
//Apply FIRM0/1 writes patches on SysNAND to protect A9LH
|
||||||
|
else if(isFirmProtEnabled) ret += patchFirmWrites(process9Offset, process9Size);
|
||||||
|
|
||||||
|
#ifndef BUILD_FOR_EXPLOIT_DEV
|
||||||
|
//Apply firmlaunch patches
|
||||||
|
ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//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 *section1 = (u8 *)firm + firm->section[1].offset;
|
||||||
|
u32 section1Size = firm->section[1].size;
|
||||||
|
u8 *section2 = (u8 *)firm + firm->section[2].offset;
|
||||||
|
u32 section2Size = firm->section[2].size;
|
||||||
|
|
||||||
|
u8 *arm9Section = (u8 *)firm + firm->section[3].offset;
|
||||||
|
|
||||||
|
// Below 3.0, do not actually do anything.
|
||||||
|
if(!ISN3DS && firmVersion < 0xC)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
ret += patchLgyK11(section1, section1Size, section2, section2Size);
|
||||||
|
|
||||||
|
// Also patch TwlBg here
|
||||||
|
mergeSection0(TWL_FIRM, 0, loadFromStorage);
|
||||||
|
firm->section[0].size = 0;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchAgbFirm(bool loadFromStorage, bool doUnitinfoPatch)
|
||||||
|
{
|
||||||
|
u8 *arm9Section = (u8 *)firm + firm->section[3].offset;
|
||||||
|
|
||||||
|
u8 *section1 = (u8 *)firm + firm->section[1].offset;
|
||||||
|
u32 section1Size = firm->section[1].size;
|
||||||
|
u8 *section2 = (u8 *)firm + firm->section[2].offset;
|
||||||
|
u32 section2Size = firm->section[2].size;
|
||||||
|
|
||||||
|
//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);
|
||||||
|
ret += patchLgyK11(section1, section1Size, section2, section2Size);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//Apply firmlaunch patches
|
||||||
|
//Doesn't work here if Luma is on SD. If you want to use SAFE_FIRM on 1.0, use Luma from NAND & uncomment this line:
|
||||||
|
//ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr);
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchPrototypeNative(FirmwareSource nandType)
|
||||||
|
{
|
||||||
|
u8 *arm9Section = (u8 *)firm + firm->section[2].offset;
|
||||||
|
|
||||||
|
//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 += patchProtoNandSignatureCheck(process9Offset, process9Size);
|
||||||
|
|
||||||
|
//Arm9 exception handlers
|
||||||
|
ret += patchArm9ExceptionHandlersInstall(arm9Section, kernel9Size);
|
||||||
|
|
||||||
|
//Apply EmuNAND patches
|
||||||
|
if(nandType != FIRMWARE_SYSNAND) ret += patchProtoEmuNand(process9Offset, process9Size);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void launchFirm(int argc, char **argv)
|
||||||
|
{
|
||||||
|
prepareArm11ForFirmlaunch();
|
||||||
|
chainload(argc, argv, firm);
|
||||||
|
}
|
||||||
39
arm9/source/firm.h
Normal file
39
arm9/source/firm.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 "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);
|
||||||
|
u32 patchPrototypeNative(FirmwareSource nandType);
|
||||||
|
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, ...);
|
||||||
144
arm9/source/font.h
Normal file
144
arm9/source/font.h
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
This file was autogenerated by raw2c.
|
||||||
|
Visit http://www.devkitpro.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#ifndef _font_h_
|
||||||
|
#define _font_h_
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
static const unsigned char font[] = {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e,
|
||||||
|
0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00,
|
||||||
|
0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x3c, 0x3c, 0x18, 0xff, 0xe7, 0x18, 0x3c, 0x00,
|
||||||
|
0x10, 0x38, 0x7c, 0xfe, 0xee, 0x10, 0x38, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00,
|
||||||
|
0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00,
|
||||||
|
0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78,
|
||||||
|
0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x08, 0x0c, 0x0a, 0x0a, 0x08, 0x78, 0xf0, 0x00,
|
||||||
|
0x18, 0x14, 0x1a, 0x16, 0x72, 0xe2, 0x0e, 0x1c, 0x10, 0x54, 0x38, 0xee, 0x38, 0x54, 0x10, 0x00,
|
||||||
|
0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00, 0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00,
|
||||||
|
0x18, 0x3c, 0x5a, 0x18, 0x5a, 0x3c, 0x18, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00,
|
||||||
|
0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x00, 0x1c, 0x22, 0x38, 0x44, 0x44, 0x38, 0x88, 0x70,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00, 0x18, 0x3c, 0x5a, 0x18, 0x5a, 0x3c, 0x18, 0x7e,
|
||||||
|
0x18, 0x3c, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x5a, 0x3c, 0x18, 0x00,
|
||||||
|
0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x24, 0x42, 0xff, 0x42, 0x24, 0x00, 0x00,
|
||||||
|
0x00, 0x10, 0x38, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x18, 0x00,
|
||||||
|
0x6c, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00,
|
||||||
|
0x10, 0x7c, 0xd0, 0x7c, 0x16, 0xfc, 0x10, 0x00, 0x00, 0x66, 0xac, 0xd8, 0x36, 0x6a, 0xcc, 0x00,
|
||||||
|
0x38, 0x4c, 0x38, 0x78, 0xce, 0xcc, 0x7a, 0x00, 0x30, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00,
|
||||||
|
0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x00,
|
||||||
|
0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xe6, 0x7c, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x7e, 0x00,
|
||||||
|
0x7c, 0xc6, 0x06, 0x1c, 0x70, 0xc6, 0xfe, 0x00, 0x7c, 0xc6, 0x06, 0x3c, 0x06, 0xc6, 0x7c, 0x00,
|
||||||
|
0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x1e, 0x00, 0xfe, 0xc0, 0xfc, 0x06, 0x06, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc0, 0xfc, 0xc6, 0xc6, 0x7c, 0x00, 0xfe, 0xc6, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0x7c, 0x00, 0x7c, 0xc6, 0xc6, 0x7e, 0x06, 0xc6, 0x7c, 0x00,
|
||||||
|
0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x10, 0x20,
|
||||||
|
0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00,
|
||||||
|
0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x78, 0xcc, 0x0c, 0x18, 0x30, 0x00, 0x30, 0x00,
|
||||||
|
0x7c, 0x82, 0x9e, 0xa6, 0x9e, 0x80, 0x7c, 0x00, 0x7c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00,
|
||||||
|
0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xfc, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00,
|
||||||
|
0xfc, 0x66, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0xfe, 0x62, 0x68, 0x78, 0x68, 0x62, 0xfe, 0x00,
|
||||||
|
0xfe, 0x62, 0x68, 0x78, 0x68, 0x60, 0xf0, 0x00, 0x7c, 0xc6, 0xc6, 0xc0, 0xce, 0xc6, 0x7e, 0x00,
|
||||||
|
0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0x1e, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, 0xe6, 0x66, 0x6c, 0x78, 0x6c, 0x66, 0xe6, 0x00,
|
||||||
|
0xf0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x82, 0xc6, 0xee, 0xfe, 0xd6, 0xc6, 0xc6, 0x00,
|
||||||
|
0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0xfc, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x06,
|
||||||
|
0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xe6, 0x00, 0x7c, 0xc6, 0xc0, 0x7c, 0x06, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7e, 0x5a, 0x5a, 0x18, 0x18, 0x18, 0x3c, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0xc6, 0xc6, 0xd6, 0xfe, 0xee, 0xc6, 0x82, 0x00,
|
||||||
|
0xc6, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6, 0x00, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00, 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00,
|
||||||
|
0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00,
|
||||||
|
0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
|
||||||
|
0x30, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
|
||||||
|
0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x00,
|
||||||
|
0x1c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00,
|
||||||
|
0x1c, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0x78,
|
||||||
|
0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0x00, 0x0c, 0x00, 0x1c, 0x0c, 0x0c, 0xcc, 0x78, 0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00,
|
||||||
|
0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0xcc, 0xfe, 0xd6, 0xd6, 0xd6, 0x00,
|
||||||
|
0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0x00, 0x00, 0xdc, 0x66, 0x66, 0x7c, 0x60, 0xf0, 0x00, 0x00, 0x7c, 0xcc, 0xcc, 0x7c, 0x0c, 0x1e,
|
||||||
|
0x00, 0x00, 0xde, 0x76, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x7c, 0xc0, 0x7c, 0x06, 0x7c, 0x00,
|
||||||
|
0x10, 0x30, 0xfc, 0x30, 0x30, 0x34, 0x18, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
|
||||||
|
0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0xc6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00,
|
||||||
|
0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8,
|
||||||
|
0x00, 0x00, 0xfc, 0x98, 0x30, 0x64, 0xfc, 0x00, 0x0e, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0e, 0x00,
|
||||||
|
0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, 0xe0, 0x30, 0x30, 0x18, 0x30, 0x30, 0xe0, 0x00,
|
||||||
|
0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc0, 0xc0, 0xc6, 0x7c, 0x18, 0x70, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
|
||||||
|
0x0e, 0x10, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00, 0x7c, 0x82, 0x38, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
|
||||||
|
0xcc, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0xe0, 0x10, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00,
|
||||||
|
0x30, 0x30, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x7c, 0xc0, 0xc0, 0x7c, 0x18, 0x70,
|
||||||
|
0x7c, 0x82, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00,
|
||||||
|
0xe0, 0x10, 0x7c, 0xc6, 0xfe, 0xc0, 0x7c, 0x00, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0x7c, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00, 0xe0, 0x10, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0xc6, 0x00, 0x7c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00, 0x38, 0x38, 0x7c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00,
|
||||||
|
0x0e, 0x10, 0xfe, 0x60, 0x78, 0x60, 0xfe, 0x00, 0x00, 0x00, 0x7c, 0x12, 0x7e, 0xd0, 0x7e, 0x00,
|
||||||
|
0x7e, 0xc8, 0xc8, 0xfe, 0xc8, 0xc8, 0xce, 0x00, 0x7c, 0x82, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0xe0, 0x10, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0x82, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0xe0, 0x10, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
|
||||||
|
0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0xc6, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x18, 0x7c, 0xd6, 0xd0, 0xd6, 0x7c, 0x18, 0x00,
|
||||||
|
0x38, 0x6c, 0x60, 0xf0, 0x60, 0xf2, 0xdc, 0x00, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x7e, 0x18, 0x00,
|
||||||
|
0xf8, 0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0x06, 0x0e, 0x1b, 0x18, 0x3c, 0x18, 0x18, 0xd8, 0x70,
|
||||||
|
0x0e, 0x10, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x0e, 0x10, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,
|
||||||
|
0x0e, 0x10, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x0e, 0x10, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00,
|
||||||
|
0x66, 0x98, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x98, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0x00,
|
||||||
|
0x38, 0x0c, 0x3c, 0x34, 0x00, 0x7e, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00,
|
||||||
|
0x30, 0x00, 0x30, 0x60, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc0, 0xc0, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0c, 0x00, 0x00, 0xc0, 0xc8, 0xd0, 0xfe, 0x46, 0x8c, 0x1e, 0x00,
|
||||||
|
0xc0, 0xc8, 0xd0, 0xec, 0x5c, 0xbe, 0x0c, 0x00, 0x18, 0x00, 0x18, 0x18, 0x3c, 0x3c, 0x18, 0x00,
|
||||||
|
0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36, 0x6c, 0xd8, 0x00, 0x00,
|
||||||
|
0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
|
||||||
|
0xdb, 0x77, 0xdb, 0xee, 0xdb, 0x77, 0xdb, 0xee, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18,
|
||||||
|
0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36,
|
||||||
|
0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00,
|
||||||
|
0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18,
|
||||||
|
0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36,
|
||||||
|
0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
|
||||||
|
0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
|
||||||
|
0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00,
|
||||||
|
0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36,
|
||||||
|
0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
|
||||||
|
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x74, 0xcc, 0xc8, 0xdc, 0x76, 0x00, 0x78, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xdc, 0x40,
|
||||||
|
0xfe, 0x62, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x02, 0x7e, 0xec, 0x6c, 0x6c, 0x48, 0x00,
|
||||||
|
0xfe, 0x62, 0x30, 0x18, 0x30, 0x62, 0xfe, 0x00, 0x00, 0x00, 0x7e, 0xd0, 0xc8, 0xc8, 0x70, 0x00,
|
||||||
|
0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xf8, 0x80, 0x00, 0x00, 0x7e, 0xd8, 0x18, 0x18, 0x10, 0x00,
|
||||||
|
0x38, 0x10, 0x7c, 0xd6, 0xd6, 0x7c, 0x10, 0x38, 0x7c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x7c, 0x00,
|
||||||
|
0x7c, 0xc6, 0xc6, 0xc6, 0x6c, 0x28, 0xee, 0x00, 0x3c, 0x22, 0x18, 0x7c, 0xcc, 0xcc, 0x78, 0x00,
|
||||||
|
0x00, 0x00, 0x66, 0x99, 0x99, 0x66, 0x00, 0x00, 0x00, 0x06, 0x7c, 0x9e, 0xf2, 0x7c, 0xc0, 0x00,
|
||||||
|
0x00, 0x00, 0x7c, 0xc0, 0xf8, 0xc0, 0x7c, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00,
|
||||||
|
0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x7e, 0x00,
|
||||||
|
0x30, 0x18, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0x00, 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0x7c, 0x00,
|
||||||
|
0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70,
|
||||||
|
0x00, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00,
|
||||||
|
0x38, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x00,
|
||||||
|
0xd8, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x30, 0xc0, 0xf0, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
|
||||||
|
};
|
||||||
|
const int font_size = sizeof(font);
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#endif //_font_h_
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
529
arm9/source/fs.c
Normal file
529
arm9/source/fs.c
Normal file
@ -0,0 +1,529 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2021 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"
|
||||||
|
#include "alignedseqmemcpy.h"
|
||||||
|
#include "i2c.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:
|
||||||
|
{
|
||||||
|
if (f_mkdir(mainDir) != FR_OK)
|
||||||
|
{
|
||||||
|
error("Failed to create luma directory.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return switchToMainDir(isSd);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mountSdCardPartition(bool switchMainDir)
|
||||||
|
{
|
||||||
|
static bool sdInitialized = false;
|
||||||
|
if (!sdInitialized)
|
||||||
|
sdInitialized = f_mount(&sdFs, "sdmc:", 1) == FR_OK;
|
||||||
|
|
||||||
|
if (sdInitialized && switchMainDir)
|
||||||
|
return f_chdrive("sdmc:") == FR_OK && switchToMainDir(true);
|
||||||
|
return sdInitialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool remountCtrNandPartition(bool switchMainDir)
|
||||||
|
{
|
||||||
|
static bool nandInitialized = false;
|
||||||
|
int res = FR_OK;
|
||||||
|
|
||||||
|
if (!nandInitialized)
|
||||||
|
{
|
||||||
|
res = f_mount(&nandFs, "nand:", 1);
|
||||||
|
nandInitialized = res == FR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nandInitialized && switchMainDir)
|
||||||
|
return f_chdrive("nand:") == FR_OK && switchToMainDir(false);
|
||||||
|
return nandInitialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unmountPartitions(void)
|
||||||
|
{
|
||||||
|
f_unmount("nand:");
|
||||||
|
f_unmount("sdmc:");
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
// Only create the last dir in the hierarchy
|
||||||
|
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 fileCopy(const char *pathSrc, const char *pathDst, bool replace, void *tmpBuffer, size_t bufferSize)
|
||||||
|
{
|
||||||
|
FIL fileSrc, fileDst;
|
||||||
|
FRESULT res;
|
||||||
|
|
||||||
|
res = f_open(&fileSrc, pathSrc, FA_READ);
|
||||||
|
if (res != FR_OK)
|
||||||
|
return true; // Succeed if the source file doesn't exist
|
||||||
|
|
||||||
|
size_t szSrc = f_size(&fileSrc), rem = szSrc;
|
||||||
|
|
||||||
|
res = f_open(&fileDst, pathDst, FA_WRITE | (replace ? FA_CREATE_ALWAYS : FA_CREATE_NEW));
|
||||||
|
|
||||||
|
if (res == FR_EXIST)
|
||||||
|
{
|
||||||
|
// We did not fail
|
||||||
|
f_close(&fileSrc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (res == FR_NO_PATH)
|
||||||
|
{
|
||||||
|
// Only create the last dir in the hierarchy
|
||||||
|
const char *c;
|
||||||
|
for (c = pathDst + strlen(pathDst); *c != '/' && c >= pathDst; --c);
|
||||||
|
if (c >= pathDst && c - pathDst <= FF_MAX_LFN && *c != '\0')
|
||||||
|
{
|
||||||
|
char path[FF_MAX_LFN + 1];
|
||||||
|
strncpy(path, pathDst, c - pathDst);
|
||||||
|
path[c - pathDst] = '\0';
|
||||||
|
res = f_mkdir(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == FR_OK)
|
||||||
|
res = f_open(&fileDst, pathDst, FA_WRITE | (replace ? FA_CREATE_ALWAYS : FA_CREATE_NEW));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res != FR_OK)
|
||||||
|
{
|
||||||
|
f_close(&fileSrc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (rem > 0)
|
||||||
|
{
|
||||||
|
size_t sz = rem >= bufferSize ? bufferSize : rem;
|
||||||
|
UINT n = 0;
|
||||||
|
|
||||||
|
res = f_read(&fileSrc, tmpBuffer, sz, &n);
|
||||||
|
if (n != sz)
|
||||||
|
res = FR_INT_ERR; // should not happen
|
||||||
|
|
||||||
|
if (res == FR_OK)
|
||||||
|
{
|
||||||
|
res = f_write(&fileDst, tmpBuffer, sz, &n);
|
||||||
|
if (n != sz)
|
||||||
|
res = FR_DENIED; // disk full
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res != FR_OK)
|
||||||
|
{
|
||||||
|
f_close(&fileSrc);
|
||||||
|
f_close(&fileDst);
|
||||||
|
f_unlink(pathDst); // oops, failed
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rem -= sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_close(&fileSrc);
|
||||||
|
f_close(&fileDst);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool createDir(const char *path)
|
||||||
|
{
|
||||||
|
FRESULT res = f_mkdir(path);
|
||||||
|
return res == FR_OK || res == FR_EXIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, bool *hasDisplayedMenu)
|
||||||
|
{
|
||||||
|
DIR dir;
|
||||||
|
|
||||||
|
*hasDisplayedMenu = false;
|
||||||
|
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();
|
||||||
|
*hasDisplayedMenu = true;
|
||||||
|
|
||||||
|
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[64],
|
||||||
|
path[128];
|
||||||
|
|
||||||
|
sprintf(folderPath, "nand:/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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 fileCopyBuffer[0x10000];
|
||||||
|
|
||||||
|
static const u8 boot9Sha256[32] = {
|
||||||
|
0x2F, 0x88, 0x74, 0x4F, 0xEE, 0xD7, 0x17, 0x85, 0x63, 0x86, 0x40, 0x0A, 0x44, 0xBB, 0xA4, 0xB9,
|
||||||
|
0xCA, 0x62, 0xE7, 0x6A, 0x32, 0xC7, 0x15, 0xD4, 0xF3, 0x09, 0xC3, 0x99, 0xBF, 0x28, 0x16, 0x6F
|
||||||
|
};
|
||||||
|
|
||||||
|
static const u8 boot11Sha256[32] = {
|
||||||
|
0x74, 0xDA, 0xAC, 0xE1, 0xF8, 0x06, 0x7B, 0x66, 0xCC, 0x81, 0xFC, 0x30, 0x7A, 0x3F, 0xDB, 0x50,
|
||||||
|
0x9C, 0xBE, 0xDC, 0x32, 0xF9, 0x03, 0xAE, 0xBE, 0x90, 0x61, 0x44, 0xDE, 0xA7, 0xA0, 0x75, 0x12
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool backupEssentialFiles(void)
|
||||||
|
{
|
||||||
|
size_t sz = sizeof(fileCopyBuffer);
|
||||||
|
|
||||||
|
u32 deviceID = *(vu32*)0x01FFB804;
|
||||||
|
char pathStart[0x20];
|
||||||
|
sprintf(pathStart, "backups/%08lX/", deviceID);
|
||||||
|
char fullPath[0x80];
|
||||||
|
|
||||||
|
// Since the other funcs in this file don't create directories recursively (only the last one),
|
||||||
|
// and nor does f_mkdir, create the directories anyway and ignore the result
|
||||||
|
f_mkdir("backups");
|
||||||
|
f_mkdir(pathStart);
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
sprintf(fullPath, "%sHWCAL0.dat", pathStart);
|
||||||
|
ok = ok && fileCopy("nand:/ro/sys/HWCAL0.dat", fullPath, false, fileCopyBuffer, sz);
|
||||||
|
sprintf(fullPath, "%sHWCAL1.dat", pathStart);
|
||||||
|
ok = ok && fileCopy("nand:/ro/sys/HWCAL1.dat", fullPath, false, fileCopyBuffer, sz);
|
||||||
|
|
||||||
|
sprintf(fullPath, "%sLocalFriendCodeSeed_A", pathStart);
|
||||||
|
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_A", fullPath, false, fileCopyBuffer, sz); // often doesn't exist
|
||||||
|
sprintf(fullPath, "%sLocalFriendCodeSeed_B", pathStart);
|
||||||
|
ok = ok && fileCopy("nand:/rw/sys/LocalFriendCodeSeed_B", fullPath, false, fileCopyBuffer, sz);
|
||||||
|
|
||||||
|
sprintf(fullPath, "%sSecureInfo_A", pathStart);
|
||||||
|
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_A", fullPath, false, fileCopyBuffer, sz);
|
||||||
|
sprintf(fullPath, "%sSecureInfo_B", pathStart);
|
||||||
|
ok = ok && fileCopy("nand:/rw/sys/SecureInfo_B", fullPath, false, fileCopyBuffer, sz); // often doesn't exist
|
||||||
|
|
||||||
|
if (!ok) return false;
|
||||||
|
|
||||||
|
alignedseqmemcpy(fileCopyBuffer, (const void *)0x10012000, 0x100);
|
||||||
|
sprintf(fullPath, "%sotp.bin", pathStart);
|
||||||
|
if (getFileSize(fullPath) != 0x100)
|
||||||
|
ok = ok && fileWrite(fileCopyBuffer, fullPath, 0x100);
|
||||||
|
|
||||||
|
if (!ok) return false;
|
||||||
|
|
||||||
|
// On dev boards, but not O3DS IS_DEBUGGER, hwcal is on an EEPROM chip accessed via I2C
|
||||||
|
u8 c = mcuConsoleInfo[0];
|
||||||
|
if (c == 2 || c == 4 || (ISN3DS && c == 5) || c == 6)
|
||||||
|
{
|
||||||
|
sprintf(fullPath, "%sHWCAL_01_EEPROM.dat", pathStart);
|
||||||
|
I2C_readRegBuf(I2C_DEV_EEPROM, 0, fileCopyBuffer, 0x1000); // Up to two instances of hwcal, with the second one @0x800
|
||||||
|
if (getFileSize(fullPath) != 0x1000)
|
||||||
|
ok = ok && fileWrite(fileCopyBuffer, fullPath, 0x1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// B9S bootrom backups
|
||||||
|
u32 hash[32/4];
|
||||||
|
sha(hash, (const void *)0x08080000, 0x10000, SHA_256_MODE);
|
||||||
|
sprintf(fullPath, "%sboot9.bin", pathStart);
|
||||||
|
if (memcmp(hash, boot9Sha256, 32) == 0 && getFileSize(fullPath) != 0x10000)
|
||||||
|
ok = ok && fileWrite((const void *)0x08080000, fullPath, 0x10000);
|
||||||
|
sha(hash, (const void *)0x08090000, 0x10000, SHA_256_MODE);
|
||||||
|
sprintf(fullPath, "%sboot11.bin", pathStart);
|
||||||
|
if (memcmp(hash, boot11Sha256, 32) == 0 && getFileSize(fullPath) != 0x10000)
|
||||||
|
ok = ok && fileWrite((const void *)0x08090000, fullPath, 0x10000);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool doLumaUpgradeProcess(void)
|
||||||
|
{
|
||||||
|
bool ok = true, ok2 = true;
|
||||||
|
|
||||||
|
// Ensure CTRNAND is mounted
|
||||||
|
remountCtrNandPartition(false);
|
||||||
|
|
||||||
|
// Try to boot.firm to CTRNAND, when applicable
|
||||||
|
#ifndef BUILD_FOR_EXPLOIT_DEV
|
||||||
|
if (isSdMode && memcmp(launchedPathForFatfs, "sdmc:", 5) == 0)
|
||||||
|
ok = fileCopy(launchedPathForFatfs, "nand:/boot.firm", true, fileCopyBuffer, sizeof(fileCopyBuffer));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Try to backup essential files
|
||||||
|
ok2 = backupEssentialFiles();
|
||||||
|
|
||||||
|
// Clean up some of the old files
|
||||||
|
fileDelete("sdmc:/luma/config.bin");
|
||||||
|
fileDelete("nand:/rw/luma/config.bin");
|
||||||
|
|
||||||
|
createDir("sdmc:/luma/payloads");
|
||||||
|
createDir("nand:/rw/luma/payloads");
|
||||||
|
|
||||||
|
return ok && ok2;
|
||||||
|
}
|
||||||
48
arm9/source/fs.h
Normal file
48
arm9/source/fs.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2021 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 mountSdCardPartition(bool switchMainDir);
|
||||||
|
bool remountCtrNandPartition(bool switchMainDir);
|
||||||
|
void unmountPartitions(void);
|
||||||
|
|
||||||
|
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 fileCopy(const char *pathSrc, const char *pathDst, bool replace, void *tmpBuffer, size_t bufferSize);
|
||||||
|
bool createDir(const char *path);
|
||||||
|
bool findPayload(char *path, u32 pressed);
|
||||||
|
bool payloadMenu(char *path, bool *hasDisplayedMenu);
|
||||||
|
u32 firmRead(void *dest, u32 firmType);
|
||||||
|
void findDumpFile(const char *folderPath, char *fileName);
|
||||||
|
|
||||||
|
bool doLumaUpgradeProcess(void);
|
||||||
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);
|
||||||
|
}
|
||||||
104
arm9/source/i2c.h
Normal file
104
arm9/source/i2c.h
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#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_LCD_TOP = 5,
|
||||||
|
I2C_DEV_LCD_BOT = 6,
|
||||||
|
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);
|
||||||
298
arm9/source/ini.c
Normal file
298
arm9/source/ini.c
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
/* inih -- simple .INI file parser
|
||||||
|
|
||||||
|
SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
Copyright (C) 2009-2020, Ben Hoyt
|
||||||
|
|
||||||
|
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
||||||
|
home page for more info:
|
||||||
|
|
||||||
|
https://github.com/benhoyt/inih
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "ini.h"
|
||||||
|
|
||||||
|
#if !INI_USE_STACK
|
||||||
|
#if INI_CUSTOM_ALLOCATOR
|
||||||
|
#include <stddef.h>
|
||||||
|
void* ini_malloc(size_t size);
|
||||||
|
void ini_free(void* ptr);
|
||||||
|
void* ini_realloc(void* ptr, size_t size);
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define ini_malloc malloc
|
||||||
|
#define ini_free free
|
||||||
|
#define ini_realloc realloc
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAX_SECTION 50
|
||||||
|
#define MAX_NAME 50
|
||||||
|
|
||||||
|
/* Used by ini_parse_string() to keep track of string parsing state. */
|
||||||
|
typedef struct {
|
||||||
|
const char* ptr;
|
||||||
|
size_t num_left;
|
||||||
|
} ini_parse_string_ctx;
|
||||||
|
|
||||||
|
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||||
|
static char* rstrip(char* s)
|
||||||
|
{
|
||||||
|
char* p = s + strlen(s);
|
||||||
|
while (p > s && isspace((unsigned char)(*--p)))
|
||||||
|
*p = '\0';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return pointer to first non-whitespace char in given string. */
|
||||||
|
static char* lskip(const char* s)
|
||||||
|
{
|
||||||
|
while (*s && isspace((unsigned char)(*s)))
|
||||||
|
s++;
|
||||||
|
return (char*)s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return pointer to first char (of chars) or inline comment in given string,
|
||||||
|
or pointer to NUL at end of string if neither found. Inline comment must
|
||||||
|
be prefixed by a whitespace character to register as a comment. */
|
||||||
|
static char* find_chars_or_comment(const char* s, const char* chars)
|
||||||
|
{
|
||||||
|
#if INI_ALLOW_INLINE_COMMENTS
|
||||||
|
int was_space = 0;
|
||||||
|
while (*s && (!chars || !strchr(chars, *s)) &&
|
||||||
|
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
|
||||||
|
was_space = isspace((unsigned char)(*s));
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
while (*s && (!chars || !strchr(chars, *s))) {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return (char*)s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Similar to strncpy, but ensures dest (size bytes) is
|
||||||
|
NUL-terminated, and doesn't pad with NULs. */
|
||||||
|
static char* strncpy0(char* dest, const char* src, size_t size)
|
||||||
|
{
|
||||||
|
/* Could use strncpy internally, but it causes gcc warnings (see issue #91) */
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < size - 1 && src[i]; i++)
|
||||||
|
dest[i] = src[i];
|
||||||
|
dest[i] = '\0';
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See documentation in header file. */
|
||||||
|
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||||
|
void* user)
|
||||||
|
{
|
||||||
|
/* Uses a fair bit of stack (use heap instead if you need to) */
|
||||||
|
#if INI_USE_STACK
|
||||||
|
char line[INI_MAX_LINE];
|
||||||
|
int max_line = INI_MAX_LINE;
|
||||||
|
#else
|
||||||
|
char* line;
|
||||||
|
size_t max_line = INI_INITIAL_ALLOC;
|
||||||
|
#endif
|
||||||
|
#if INI_ALLOW_REALLOC && !INI_USE_STACK
|
||||||
|
char* new_line;
|
||||||
|
size_t offset;
|
||||||
|
#endif
|
||||||
|
char section[MAX_SECTION] = "";
|
||||||
|
char prev_name[MAX_NAME] = "";
|
||||||
|
|
||||||
|
char* start;
|
||||||
|
char* end;
|
||||||
|
char* name;
|
||||||
|
char* value;
|
||||||
|
int lineno = 0;
|
||||||
|
int error = 0;
|
||||||
|
|
||||||
|
#if !INI_USE_STACK
|
||||||
|
line = (char*)ini_malloc(INI_INITIAL_ALLOC);
|
||||||
|
if (!line) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if INI_HANDLER_LINENO
|
||||||
|
#define HANDLER(u, s, n, v) handler(u, s, n, v, lineno)
|
||||||
|
#else
|
||||||
|
#define HANDLER(u, s, n, v) handler(u, s, n, v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Scan through stream line by line */
|
||||||
|
while (reader(line, (int)max_line, stream) != NULL) {
|
||||||
|
#if INI_ALLOW_REALLOC && !INI_USE_STACK
|
||||||
|
offset = strlen(line);
|
||||||
|
while (offset == max_line - 1 && line[offset - 1] != '\n') {
|
||||||
|
max_line *= 2;
|
||||||
|
if (max_line > INI_MAX_LINE)
|
||||||
|
max_line = INI_MAX_LINE;
|
||||||
|
new_line = ini_realloc(line, max_line);
|
||||||
|
if (!new_line) {
|
||||||
|
ini_free(line);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
line = new_line;
|
||||||
|
if (reader(line + offset, (int)(max_line - offset), stream) == NULL)
|
||||||
|
break;
|
||||||
|
if (max_line >= INI_MAX_LINE)
|
||||||
|
break;
|
||||||
|
offset += strlen(line + offset);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
lineno++;
|
||||||
|
|
||||||
|
start = line;
|
||||||
|
#if INI_ALLOW_BOM
|
||||||
|
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
|
||||||
|
(unsigned char)start[1] == 0xBB &&
|
||||||
|
(unsigned char)start[2] == 0xBF) {
|
||||||
|
start += 3;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
start = lskip(rstrip(start));
|
||||||
|
|
||||||
|
if (strchr(INI_START_COMMENT_PREFIXES, *start)) {
|
||||||
|
/* Start-of-line comment */
|
||||||
|
}
|
||||||
|
#if INI_ALLOW_MULTILINE
|
||||||
|
else if (*prev_name && *start && start > line) {
|
||||||
|
/* Non-blank line with leading whitespace, treat as continuation
|
||||||
|
of previous name's value (as per Python configparser). */
|
||||||
|
if (!HANDLER(user, section, prev_name, start) && !error)
|
||||||
|
error = lineno;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else if (*start == '[') {
|
||||||
|
/* A "[section]" line */
|
||||||
|
end = find_chars_or_comment(start + 1, "]");
|
||||||
|
if (*end == ']') {
|
||||||
|
*end = '\0';
|
||||||
|
strncpy0(section, start + 1, sizeof(section));
|
||||||
|
*prev_name = '\0';
|
||||||
|
#if INI_CALL_HANDLER_ON_NEW_SECTION
|
||||||
|
if (!HANDLER(user, section, NULL, NULL) && !error)
|
||||||
|
error = lineno;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (!error) {
|
||||||
|
/* No ']' found on section line */
|
||||||
|
error = lineno;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (*start) {
|
||||||
|
/* Not a comment, must be a name[=:]value pair */
|
||||||
|
end = find_chars_or_comment(start, "=:");
|
||||||
|
if (*end == '=' || *end == ':') {
|
||||||
|
*end = '\0';
|
||||||
|
name = rstrip(start);
|
||||||
|
value = end + 1;
|
||||||
|
#if INI_ALLOW_INLINE_COMMENTS
|
||||||
|
end = find_chars_or_comment(value, NULL);
|
||||||
|
if (*end)
|
||||||
|
*end = '\0';
|
||||||
|
#endif
|
||||||
|
value = lskip(value);
|
||||||
|
rstrip(value);
|
||||||
|
|
||||||
|
/* Valid name[=:]value pair found, call handler */
|
||||||
|
strncpy0(prev_name, name, sizeof(prev_name));
|
||||||
|
if (!HANDLER(user, section, name, value) && !error)
|
||||||
|
error = lineno;
|
||||||
|
}
|
||||||
|
else if (!error) {
|
||||||
|
/* No '=' or ':' found on name[=:]value line */
|
||||||
|
#if INI_ALLOW_NO_VALUE
|
||||||
|
*end = '\0';
|
||||||
|
name = rstrip(start);
|
||||||
|
if (!HANDLER(user, section, name, NULL) && !error)
|
||||||
|
error = lineno;
|
||||||
|
#else
|
||||||
|
error = lineno;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if INI_STOP_ON_FIRST_ERROR
|
||||||
|
if (error)
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !INI_USE_STACK
|
||||||
|
ini_free(line);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See documentation in header file. */
|
||||||
|
int ini_parse_file(FILE* file, ini_handler handler, void* user)
|
||||||
|
{
|
||||||
|
return ini_parse_stream((ini_reader)fgets, file, handler, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See documentation in header file. */
|
||||||
|
int ini_parse(const char* filename, ini_handler handler, void* user)
|
||||||
|
{
|
||||||
|
FILE* file;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
file = fopen(filename, "r");
|
||||||
|
if (!file)
|
||||||
|
return -1;
|
||||||
|
error = ini_parse_file(file, handler, user);
|
||||||
|
fclose(file);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* An ini_reader function to read the next line from a string buffer. This
|
||||||
|
is the fgets() equivalent used by ini_parse_string(). */
|
||||||
|
static char* ini_reader_string(char* str, int num, void* stream) {
|
||||||
|
ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream;
|
||||||
|
const char* ctx_ptr = ctx->ptr;
|
||||||
|
size_t ctx_num_left = ctx->num_left;
|
||||||
|
char* strp = str;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
if (ctx_num_left == 0 || num < 2)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
while (num > 1 && ctx_num_left != 0) {
|
||||||
|
c = *ctx_ptr++;
|
||||||
|
ctx_num_left--;
|
||||||
|
*strp++ = c;
|
||||||
|
if (c == '\n')
|
||||||
|
break;
|
||||||
|
num--;
|
||||||
|
}
|
||||||
|
|
||||||
|
*strp = '\0';
|
||||||
|
ctx->ptr = ctx_ptr;
|
||||||
|
ctx->num_left = ctx_num_left;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See documentation in header file. */
|
||||||
|
int ini_parse_string(const char* string, ini_handler handler, void* user) {
|
||||||
|
ini_parse_string_ctx ctx;
|
||||||
|
|
||||||
|
ctx.ptr = string;
|
||||||
|
ctx.num_left = strlen(string);
|
||||||
|
return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler,
|
||||||
|
user);
|
||||||
|
}
|
||||||
157
arm9/source/ini.h
Normal file
157
arm9/source/ini.h
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
/* inih -- simple .INI file parser
|
||||||
|
|
||||||
|
SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
Copyright (C) 2009-2020, Ben Hoyt
|
||||||
|
|
||||||
|
inih is released under the New BSD license (see LICENSE.txt). Go to the project
|
||||||
|
home page for more info:
|
||||||
|
|
||||||
|
https://github.com/benhoyt/inih
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INI_H
|
||||||
|
#define INI_H
|
||||||
|
|
||||||
|
/* Make this header file easier to include in C++ code */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Nonzero if ini_handler callback should accept lineno parameter. */
|
||||||
|
#ifndef INI_HANDLER_LINENO
|
||||||
|
#define INI_HANDLER_LINENO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Typedef for prototype of handler function. */
|
||||||
|
#if INI_HANDLER_LINENO
|
||||||
|
typedef int (*ini_handler)(void* user, const char* section,
|
||||||
|
const char* name, const char* value,
|
||||||
|
int lineno);
|
||||||
|
#else
|
||||||
|
typedef int (*ini_handler)(void* user, const char* section,
|
||||||
|
const char* name, const char* value);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Typedef for prototype of fgets-style reader function. */
|
||||||
|
typedef char* (*ini_reader)(char* str, int num, void* stream);
|
||||||
|
|
||||||
|
/* Parse given INI-style file. May have [section]s, name=value pairs
|
||||||
|
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
||||||
|
is "" if name=value pair parsed before any section heading. name:value
|
||||||
|
pairs are also supported as a concession to Python's configparser.
|
||||||
|
|
||||||
|
For each name=value pair parsed, call handler function with given user
|
||||||
|
pointer as well as section, name, and value (data only valid for duration
|
||||||
|
of handler call). Handler should return nonzero on success, zero on error.
|
||||||
|
|
||||||
|
Returns 0 on success, line number of first error on parse error (doesn't
|
||||||
|
stop on first error), -1 on file open error, or -2 on memory allocation
|
||||||
|
error (only when INI_USE_STACK is zero).
|
||||||
|
*/
|
||||||
|
int ini_parse(const char* filename, ini_handler handler, void* user);
|
||||||
|
|
||||||
|
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
|
||||||
|
close the file when it's finished -- the caller must do that. */
|
||||||
|
int ini_parse_file(FILE* file, ini_handler handler, void* user);
|
||||||
|
|
||||||
|
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
||||||
|
filename. Used for implementing custom or string-based I/O (see also
|
||||||
|
ini_parse_string). */
|
||||||
|
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
||||||
|
void* user);
|
||||||
|
|
||||||
|
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
|
||||||
|
instead of a file. Useful for parsing INI data from a network socket or
|
||||||
|
already in memory. */
|
||||||
|
int ini_parse_string(const char* string, ini_handler handler, void* user);
|
||||||
|
|
||||||
|
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
||||||
|
configparser. If allowed, ini_parse() will call the handler with the same
|
||||||
|
name for each subsequent line parsed. */
|
||||||
|
#ifndef INI_ALLOW_MULTILINE
|
||||||
|
#define INI_ALLOW_MULTILINE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
||||||
|
the file. See https://github.com/benhoyt/inih/issues/21 */
|
||||||
|
#ifndef INI_ALLOW_BOM
|
||||||
|
#define INI_ALLOW_BOM 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Chars that begin a start-of-line comment. Per Python configparser, allow
|
||||||
|
both ; and # comments at the start of a line by default. */
|
||||||
|
#ifndef INI_START_COMMENT_PREFIXES
|
||||||
|
#define INI_START_COMMENT_PREFIXES ";#"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to allow inline comments (with valid inline comment characters
|
||||||
|
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
|
||||||
|
Python 3.2+ configparser behaviour. */
|
||||||
|
#ifndef INI_ALLOW_INLINE_COMMENTS
|
||||||
|
#define INI_ALLOW_INLINE_COMMENTS 1
|
||||||
|
#endif
|
||||||
|
#ifndef INI_INLINE_COMMENT_PREFIXES
|
||||||
|
#define INI_INLINE_COMMENT_PREFIXES ";"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
|
||||||
|
#ifndef INI_USE_STACK
|
||||||
|
#define INI_USE_STACK 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Maximum line length for any line in INI file (stack or heap). Note that
|
||||||
|
this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
|
||||||
|
#ifndef INI_MAX_LINE
|
||||||
|
#define INI_MAX_LINE 200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
|
||||||
|
fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
|
||||||
|
zero. */
|
||||||
|
#ifndef INI_ALLOW_REALLOC
|
||||||
|
#define INI_ALLOW_REALLOC 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
|
||||||
|
is zero. */
|
||||||
|
#ifndef INI_INITIAL_ALLOC
|
||||||
|
#define INI_INITIAL_ALLOC 200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Stop parsing on first error (default is to keep parsing). */
|
||||||
|
#ifndef INI_STOP_ON_FIRST_ERROR
|
||||||
|
#define INI_STOP_ON_FIRST_ERROR 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to call the handler at the start of each new section (with
|
||||||
|
name and value NULL). Default is to only call the handler on
|
||||||
|
each name=value pair. */
|
||||||
|
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
|
||||||
|
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
|
||||||
|
call the handler with value NULL in this case. Default is to treat
|
||||||
|
no-value lines as an error. */
|
||||||
|
#ifndef INI_ALLOW_NO_VALUE
|
||||||
|
#define INI_ALLOW_NO_VALUE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory
|
||||||
|
allocation functions (INI_USE_STACK must also be 0). These functions must
|
||||||
|
have the same signatures as malloc/free/realloc and behave in a similar
|
||||||
|
way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */
|
||||||
|
#ifndef INI_CUSTOM_ALLOCATOR
|
||||||
|
#define INI_CUSTOM_ALLOCATOR 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* INI_H */
|
||||||
40
arm9/source/large_patches.h
Normal file
40
arm9/source/large_patches.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
extern const u8 emunandPatch[], emunandProtoPatch[], emunandProtoCidPatch[];
|
||||||
|
extern const u8 emunandProtoPatch238[];
|
||||||
|
extern const u32 emunandPatchSize, emunandPatchBssSize;
|
||||||
|
extern u32 emunandPatchSdmmcStructPtr, emunandPatchNandOffset, emunandPatchNcsdHeaderOffset;
|
||||||
|
extern u32 emunandPatchNandCid[4];
|
||||||
|
|
||||||
|
extern const u8 rebootPatch[];
|
||||||
|
extern const u32 rebootPatchSize;
|
||||||
|
extern u32 rebootPatchFopenPtr;
|
||||||
|
extern u16 rebootPatchFileName[80+1];
|
||||||
227
arm9/source/large_patches.s
Normal file
227
arm9/source/large_patches.s
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
|
||||||
|
@ 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
|
||||||
399
arm9/source/main.c
Normal file
399
arm9/source/main.c
Normal file
@ -0,0 +1,399 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2023 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 "deliver_arg.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "fmt.h"
|
||||||
|
#include "fatfs/sdmmc/sdmmc.h"
|
||||||
|
|
||||||
|
extern u8 __itcm_start__[], __itcm_lma__[], __itcm_bss_start__[], __itcm_end__[];
|
||||||
|
|
||||||
|
extern CfgData configData;
|
||||||
|
extern ConfigurationStatus needConfig;
|
||||||
|
|
||||||
|
bool isSdMode;
|
||||||
|
char launchedPathForFatfs[256];
|
||||||
|
u16 launchedPath[80+1];
|
||||||
|
BootType bootType;
|
||||||
|
|
||||||
|
u16 mcuFwVersion;
|
||||||
|
u8 mcuConsoleInfo[9];
|
||||||
|
|
||||||
|
void main(int argc, char **argv, u32 magicWord)
|
||||||
|
{
|
||||||
|
bool isFirmProtEnabled = true,
|
||||||
|
isSafeMode = false,
|
||||||
|
needToInitSd = false,
|
||||||
|
isNoForceFlagSet = false,
|
||||||
|
isInvalidLoader = false,
|
||||||
|
isNtrBoot = false;
|
||||||
|
FirmwareType firmType = NATIVE_FIRM;
|
||||||
|
FirmwareSource nandType = FIRMWARE_SYSNAND;
|
||||||
|
u32 emunandIndex = 0;
|
||||||
|
|
||||||
|
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;
|
||||||
|
strncpy(launchedPathForFatfs, argv[0], sizeof(launchedPathForFatfs) - 1);
|
||||||
|
launchedPathForFatfs[sizeof(launchedPathForFatfs) - 1] = 0;
|
||||||
|
|
||||||
|
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];
|
||||||
|
launchedPathForFatfs[i] = (u8)p[i]; // UCS-2 to ascii. Meh.
|
||||||
|
}
|
||||||
|
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];
|
||||||
|
strcpy(launchedPathForFatfs, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
u8 mcuFwVerHi = I2C_readReg(I2C_DEV_MCU, 0) - 0x10;
|
||||||
|
u8 mcuFwVerLo = I2C_readReg(I2C_DEV_MCU, 1);
|
||||||
|
mcuFwVersion = ((u16)mcuFwVerHi << 16) | mcuFwVerLo;
|
||||||
|
|
||||||
|
// Check if fw is older than factory. See https://www.3dbrew.org/wiki/MCU_Services#MCU_firmware_versions for a table
|
||||||
|
if (mcuFwVerHi < 1) error("Unsupported MCU FW version %d.%d.", (int)mcuFwVerHi, (int)mcuFwVerLo);
|
||||||
|
|
||||||
|
I2C_readRegBuf(I2C_DEV_MCU, 0x7F, mcuConsoleInfo, 9);
|
||||||
|
|
||||||
|
if(isInvalidLoader) error("Launched using an unsupported loader.");
|
||||||
|
|
||||||
|
installArm9Handlers();
|
||||||
|
|
||||||
|
if(memcmp(launchedPath, u"sdmc", 8) == 0)
|
||||||
|
{
|
||||||
|
if(!mountSdCardPartition(true)) error("Failed to mount SD.");
|
||||||
|
isSdMode = true;
|
||||||
|
}
|
||||||
|
else if(memcmp(launchedPath, u"nand", 8) == 0)
|
||||||
|
{
|
||||||
|
if(!remountCtrNandPartition(true)) error("Failed to mount CTRNAND.");
|
||||||
|
isSdMode = false;
|
||||||
|
}
|
||||||
|
else if(bootType == NTR || memcmp(launchedPath, u"firm", 8) == 0)
|
||||||
|
{
|
||||||
|
if(mountSdCardPartition(true)) isSdMode = true;
|
||||||
|
else if(remountCtrNandPartition(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;
|
||||||
|
emunandIndex = BOOTCFG_EMUINDEX;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
u32 bootenv = CFG_BOOTENV;
|
||||||
|
bool validTlnc = bootenv == 3 && hasValidTlncAutobootParams();
|
||||||
|
|
||||||
|
if (validTlnc)
|
||||||
|
needToInitSd = true;
|
||||||
|
|
||||||
|
//Always force a SysNAND boot when quitting AGB_FIRM
|
||||||
|
if(bootenv == 7)
|
||||||
|
{
|
||||||
|
nandType = FIRMWARE_SYSNAND;
|
||||||
|
|
||||||
|
// Prevent multiple boot options-forcing
|
||||||
|
// This bit is a bit weird. Basically, as you return to Home Menu by pressing either
|
||||||
|
// the HOME or POWER button, nandType will be overridden to "SysNAND" (needed). But,
|
||||||
|
// if you reboot again (e.g. via Rosalina menu), it'll use your default settings.
|
||||||
|
if(nandType != BOOTCFG_NAND) isNoForceFlagSet = true;
|
||||||
|
|
||||||
|
goto boot;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure homebrew autoboot (if deliver arg ends up not containing anything)
|
||||||
|
if (bootenv == 1 && MULTICONFIG(AUTOBOOTMODE) != 0)
|
||||||
|
configureHomebrewAutoboot();
|
||||||
|
|
||||||
|
/* Force the last used boot options if doing autolaunch from TWL, or unless a button is pressed
|
||||||
|
or the no-forcing flag is set */
|
||||||
|
if(validTlnc || !(pressed || BOOTCFG_NOFORCEFLAG))
|
||||||
|
{
|
||||||
|
nandType = (FirmwareSource)BOOTCFG_NAND;
|
||||||
|
emunandIndex = BOOTCFG_EMUINDEX;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
isSafeMode = true;
|
||||||
|
needToInitSd = true;
|
||||||
|
|
||||||
|
goto boot;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set-up autoboot
|
||||||
|
if (MULTICONFIG(AUTOBOOTMODE) != 0)
|
||||||
|
configureHomebrewAutoboot();
|
||||||
|
|
||||||
|
//If booting from CTRNAND, always use SysNAND
|
||||||
|
if(!isSdMode) nandType = FIRMWARE_SYSNAND;
|
||||||
|
else 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)
|
||||||
|
{
|
||||||
|
switch(pressed & DPAD_BUTTONS)
|
||||||
|
{
|
||||||
|
case BUTTON_UP:
|
||||||
|
emunandIndex = 0;
|
||||||
|
break;
|
||||||
|
case BUTTON_RIGHT:
|
||||||
|
emunandIndex = 1;
|
||||||
|
break;
|
||||||
|
case BUTTON_DOWN:
|
||||||
|
emunandIndex = 2;
|
||||||
|
break;
|
||||||
|
case BUTTON_LEFT:
|
||||||
|
emunandIndex = 3;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
emunandIndex = MULTICONFIG(DEFAULTEMU);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boot:
|
||||||
|
|
||||||
|
//If we need to boot EmuNAND, make sure it exists
|
||||||
|
if(nandType != FIRMWARE_SYSNAND)
|
||||||
|
{
|
||||||
|
locateEmuNand(&nandType, &emunandIndex, true);
|
||||||
|
if(nandType == FIRMWARE_EMUNAND && (*(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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrNandLocation = nandType; // for CTRNAND partition
|
||||||
|
|
||||||
|
if(bootType != FIRMLAUNCH)
|
||||||
|
{
|
||||||
|
configData.bootConfig = ((bootType == NTR ? 1 : 0) << 4) | ((u32)isNoForceFlagSet << 3) | ((u32)emunandIndex << 1) | (u32)nandType;
|
||||||
|
writeConfig(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES);
|
||||||
|
u32 firmVersion = loadNintendoFirm(&firmType, nandType, 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;
|
||||||
|
case NATIVE_PROTOTYPE:
|
||||||
|
res = patchPrototypeNative(nandType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res != 0) error("Failed to apply %u FIRM patch(es).", res);
|
||||||
|
|
||||||
|
unmountPartitions();
|
||||||
|
if(bootType != FIRMLAUNCH) deinitScreens();
|
||||||
|
launchFirm(0, NULL);
|
||||||
|
}
|
||||||
80
arm9/source/memory.c
Normal file
80
arm9/source/memory.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *copyFromLegacyModeFcram(void *dst, const void *src, size_t size)
|
||||||
|
{
|
||||||
|
// Copy 2 bytes with a stride of 8
|
||||||
|
const u16 *src16 = (const u16 *)src;
|
||||||
|
u16 *dst16 = (u16 *)dst;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < size / 2; i++)
|
||||||
|
dst16[i] = src16[4 * i];
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *copyToLegacyModeFcram(void *dst, const void *src, size_t size)
|
||||||
|
{
|
||||||
|
// Copy 2 bytes with a stride of 8
|
||||||
|
const u16 *src16 = (const u16 *)src;
|
||||||
|
u16 *dst16 = (u16 *)dst;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < size / 2; i++)
|
||||||
|
dst16[4 * i] = src16[i];
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
38
arm9/source/memory.h
Normal file
38
arm9/source/memory.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
void *copyFromLegacyModeFcram(void *dst, const void *src, size_t size);
|
||||||
|
void *copyToLegacyModeFcram(void *dst, const void *src, size_t size);
|
||||||
898
arm9/source/patches.c
Normal file
898
arm9/source/patches.c
Normal file
@ -0,0 +1,898 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
extern u16 launchedPath[];
|
||||||
|
extern u32 firmProtoVersion;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
*process9MemAddr = off->exHeader.systemControlInfo.textCodeSet.address;
|
||||||
|
|
||||||
|
// Prototype FW has a different NCCH format
|
||||||
|
if (firmProtoVersion && firmProtoVersion <= 243)
|
||||||
|
{
|
||||||
|
*process9Size = off->ncch.exeFsSize;
|
||||||
|
return (u8 *)off + off->ncch.exeFsOffset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*process9Size = (off->ncch.exeFsSize - 1) * 0x200;
|
||||||
|
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;
|
||||||
|
u32 splashDurationMsec;
|
||||||
|
s8 volumeSliderOverride;
|
||||||
|
u64 hbldr3dsxTitleId;
|
||||||
|
u32 rosalinaMenuCombo;
|
||||||
|
u32 pluginLoaderFlags;
|
||||||
|
s16 ntpTzOffetMinutes;
|
||||||
|
|
||||||
|
ScreenFiltersCfgData topScreenFilter;
|
||||||
|
ScreenFiltersCfgData bottomScreenFilter;
|
||||||
|
|
||||||
|
u64 autobootTwlTitleId;
|
||||||
|
u8 autobootCtrAppmemtype;
|
||||||
|
|
||||||
|
u16 launchedPath[80+1];
|
||||||
|
} 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->splashDurationMsec = configData.splashDurationMsec;
|
||||||
|
info->volumeSliderOverride = configData.volumeSliderOverride;
|
||||||
|
info->hbldr3dsxTitleId = configData.hbldr3dsxTitleId;
|
||||||
|
info->rosalinaMenuCombo = configData.rosalinaMenuCombo;
|
||||||
|
info->pluginLoaderFlags = configData.pluginLoaderFlags;
|
||||||
|
info->ntpTzOffetMinutes = configData.ntpTzOffetMinutes;
|
||||||
|
info->topScreenFilter = configData.topScreenFilter;
|
||||||
|
info->bottomScreenFilter = configData.bottomScreenFilter;
|
||||||
|
info->autobootTwlTitleId = configData.autobootTwlTitleId;
|
||||||
|
info->autobootCtrAppmemtype = configData.autobootCtrAppmemtype;
|
||||||
|
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;
|
||||||
|
|
||||||
|
memcpy(info->launchedPath, launchedPath, sizeof(info->launchedPath));
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (ISN3DS)
|
||||||
|
{
|
||||||
|
// Patch SvcSetProcessIdealProcessor and SvcCreate thread to always allow
|
||||||
|
// for core2 and core3 to be used. Normally, processes with the 0x2000 kernel flag
|
||||||
|
// have access to core2, and BASE processes have access to both core2 and core3.
|
||||||
|
// We're patching the if (memory region == BASE) check to be always true.
|
||||||
|
off = (u32 *)pos;
|
||||||
|
for (u32 i = 0; i < 2 && (u8 *)off < pos + size; i++)
|
||||||
|
{
|
||||||
|
// cmp r2, #0x300; beq...
|
||||||
|
for (; (off[0] != 0xE3520C03 || off[1] != 0x0A000003) && (u8 *)off < pos + size; off++);
|
||||||
|
if ((u8 *)off > pos + size)
|
||||||
|
return 1;
|
||||||
|
off[1] = 0xEA000003;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 oldKipSectionSize, u32 newKipSectionSize, u32 numKips, 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] = (u8)numKips;
|
||||||
|
|
||||||
|
u32 *off32;
|
||||||
|
for(off32 = (u32 *)(off - 3); *off32 != 0xE59F0000; off32++);
|
||||||
|
off32 += 2;
|
||||||
|
off32[1] = off32[0] + newKipSectionSize;
|
||||||
|
for(; *off32 != oldKipSectionSize; off32++);
|
||||||
|
*off32 = ((newKipSectionSize + 0x1FF) >> 9) << 9;
|
||||||
|
|
||||||
|
off = memsearch(pos, modulePidPattern, size, 4);
|
||||||
|
|
||||||
|
if(off == NULL) return 1;
|
||||||
|
|
||||||
|
off[0xB] = (u8)numKips;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchK11ModuleLoadingLgy(u32 newKipSectionSize, u8 *pos, u32 size)
|
||||||
|
{
|
||||||
|
// Patch the function where TwlBg/AgbBg is copied from 18000000 (VRAM) to 21000000 (FCRAM).
|
||||||
|
// This is where we can also automatically obtain the section size
|
||||||
|
|
||||||
|
u16 *off = (u16 *)pos;
|
||||||
|
for (; (u8 *)off < pos + size && (off[0] != 0x06C9 || off[1] != 0x0600); off++);
|
||||||
|
if ((u8 *)off >= pos + size)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
off += 7;
|
||||||
|
u32 oldKipSectionSize = *(u32 *)off;
|
||||||
|
*(u32 *)off = newKipSectionSize;
|
||||||
|
off += 2;
|
||||||
|
|
||||||
|
u32 *off2 = (u32 *)off;
|
||||||
|
for (; (u8 *)off2 < pos + size && *off2 != oldKipSectionSize; off2++);
|
||||||
|
if ((u8 *)off2 >= pos + size)
|
||||||
|
return 4;
|
||||||
|
*off2 = newKipSectionSize;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void patchTwlBg(u8 *pos, u32 size)
|
||||||
|
{
|
||||||
|
// You can use the following Python code to convert something like below
|
||||||
|
// into twl_upscaling_filter.bin:
|
||||||
|
// import struct; open("twl_upscaling_filter.bin", "wb+").write(struct.pack("<30H", [array contents]))
|
||||||
|
static const u16 nintendoFilterTwl[] = {
|
||||||
|
0x0000, 0x004E, 0x011D, 0x01E3, 0x01C1,
|
||||||
|
0x0000, 0xFCA5, 0xF8D0, 0xF69D, 0xF873,
|
||||||
|
0x0000, 0x0D47, 0x1E35, 0x2F08, 0x3B6F,
|
||||||
|
0x4000, 0x3B6F, 0x2F08, 0x1E35, 0x0D47,
|
||||||
|
0x0000, 0xF873, 0xF69D, 0xF8D0, 0xFCA5,
|
||||||
|
0x0000, 0x01C1, 0x01E3, 0x011D, 0x004E,
|
||||||
|
};
|
||||||
|
|
||||||
|
// "error" func doesn't seem to work here
|
||||||
|
if (CONFIG(ENABLEDSIEXTFILTER))
|
||||||
|
{
|
||||||
|
u16 filter[5*6] = { 0 };
|
||||||
|
u32 rd = fileRead(filter, "twl_upscaling_filter.bin", sizeof(filter));
|
||||||
|
if (rd == sizeof(filter))
|
||||||
|
{
|
||||||
|
// else error("Failed to apply enable_dsi_external_filter:\n\ntwl_upscaling_filter.bin is missing or invalid.");
|
||||||
|
u8 *off = memsearch(pos, nintendoFilterTwl, size, sizeof(nintendoFilterTwl));
|
||||||
|
if (off != NULL)
|
||||||
|
memcpy(off, filter, sizeof(filter));
|
||||||
|
// else error("Failed to apply enable_dsi_external_filter.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchLgyK11(u8 *section1, u32 section1Size, u8 *section2, u32 section2Size)
|
||||||
|
{
|
||||||
|
u32 *off;
|
||||||
|
|
||||||
|
// Fix a bug where Legacy K11 maps user TLS with "user no access" permissions
|
||||||
|
// Map it as RWX (just like the rest of other user-accessible pages) instead
|
||||||
|
for (off = (u32 *)section1; (u8 *)off <= section1 + section1Size && *off != 0xE0100000; off++);
|
||||||
|
|
||||||
|
if ((u8 *)off >= section1 + section1Size)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
++off;
|
||||||
|
|
||||||
|
*off &= ~0x231; // clear APX mask and XN
|
||||||
|
*off |= 0x030; // re-set APX (to user/kernel RW)
|
||||||
|
|
||||||
|
// Patch two pointer-to-bool to point to a non-zero byte, enabling user exception handling.
|
||||||
|
// It is impossible to enable it by normal means, otherwise
|
||||||
|
for (off = (u32 *)section2; (u8 *)off <= section2 + section2Size && *off != 0x100021F; off++);
|
||||||
|
if ((u8 *)off >= section2 + section2Size)
|
||||||
|
return 1;
|
||||||
|
off[1] = 0xFFFF0F00;
|
||||||
|
off[2] = 0xFFFF0F04;
|
||||||
|
|
||||||
|
// Dispatch-to-user code checks for memory block type and permissions (etc.), but
|
||||||
|
// LGY K11 doesn't do any memory management, so these checks will always fail.
|
||||||
|
// Patch with b +0x38 to skip all those checks
|
||||||
|
u16 *off2;
|
||||||
|
for (off2 = (u16 *)section2; (u8 *)off2 <= section2 + section2Size && (off2[0] != 0xDB1F || off2[1] != 0x4915); off2++);
|
||||||
|
if ((u8 *)off2 >= section2 + section2Size)
|
||||||
|
return 1;
|
||||||
|
*off2 = 0xE01A;
|
||||||
|
|
||||||
|
// Patch kernelpanic to skip devunit check, so that it sets the LCD fill regs
|
||||||
|
// which are useful to detect such panics
|
||||||
|
u16 *off3;
|
||||||
|
for (off3 = (u16 *)section1; (u8 *)off3 <= section1 + section1Size && (off3[0] != 0x481D || off3[1] != 0xB570); off3++);
|
||||||
|
if ((u8 *)off3 >= section1 + section1Size)
|
||||||
|
return 1;
|
||||||
|
off3[2] = 0x2001; // movs r0, #1
|
||||||
|
|
||||||
|
// Patch kernel to avoid allocating the two "configuration memory" pages, freeing
|
||||||
|
// 0x2000 bytes of kernel "heap" (which is 0xD000 AXIWRAM bytes on LGY K11 instead
|
||||||
|
// of the entire FCRAM on NFIRM). This is indeed a bug because if prevents two of the
|
||||||
|
// 12 KThread objects from being created
|
||||||
|
u16 *off4;
|
||||||
|
for (off4 = (u16 *)section1; (u8 *)off4 <= section1 + section1Size && (off4[0] != 0xB570 || off4[1] != 0x2200); off4++);
|
||||||
|
if ((u8 *)off4 >= section1 + section1Size)
|
||||||
|
return 1;
|
||||||
|
*off4 = 0x4770; // bx lr
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 patchProtoNandSignatureCheck(u8 *pos, u32 size) {
|
||||||
|
if (firmProtoVersion == 243) {
|
||||||
|
static const u8 pattern[] = {0x08, 0x31, 0x9F, 0xE5};
|
||||||
|
|
||||||
|
// Signature check function returns 0 if failed and 1 if succeeded.
|
||||||
|
// Proc9 breaks if the returned value is 0, change it to break if
|
||||||
|
// the returned value is 2 (never).
|
||||||
|
u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||||
|
if (!off)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
off[0x20] = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (firmProtoVersion == 238) { // SDK 0.10
|
||||||
|
// Same patch as for v243 ported to the different ncsd_read() function
|
||||||
|
static const u8 pattern[] = {
|
||||||
|
0x00, 0x11, 0x9f, 0xe5,
|
||||||
|
0x00, 0x51, 0x9f, 0xe5,
|
||||||
|
};
|
||||||
|
|
||||||
|
u8 *off = memsearch(pos, pattern, size, sizeof(pattern));
|
||||||
|
if (!off)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
off[0x20] = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
else return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
72
arm9/source/patches.h
Normal file
72
arm9/source/patches.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* Signature patches for prototype FW by PabloMK7
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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 oldKipSectionSize, u32 newKipSectionSize, u32 numKips, u8 *pos, u32 size);
|
||||||
|
u32 patchK11ModuleLoadingLgy(u32 newKipSectionSize, u8 *pos, 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);
|
||||||
|
void patchTwlBg(u8 *pos, u32 size); // silently fails
|
||||||
|
u32 patchLgyK11(u8 *section1, u32 section1Size, u8 *section2, u32 section2Size);
|
||||||
|
u32 patchProtoNandSignatureCheck(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);
|
||||||
156
arm9/source/screen.c
Normal file
156
arm9/source/screen.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
// Backlight voltage off
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 0x14);
|
||||||
|
wait(50);
|
||||||
|
|
||||||
|
// LCD panel voltage off
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 0x01);
|
||||||
|
wait(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Fragile code, needs proper fix/total rewrite of the baremetal components anyway
|
||||||
|
// Assume controller revision is not 0x00 for either screen (this revision is extremely
|
||||||
|
// old and shouldn't be seen in retail units nor normal devunits)
|
||||||
|
|
||||||
|
// Controller reset off
|
||||||
|
I2C_writeReg(I2C_DEV_LCD_TOP, 0xFE, 0xAA);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD_BOT, 0xFE, 0xAA);
|
||||||
|
wait(5);
|
||||||
|
|
||||||
|
// Controller power on
|
||||||
|
I2C_writeReg(I2C_DEV_LCD_TOP, 0x01, 0x10);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD_BOT, 0x01, 0x10);
|
||||||
|
wait(5);
|
||||||
|
|
||||||
|
// Clear error flag
|
||||||
|
I2C_writeReg(I2C_DEV_LCD_TOP, 0x60, 0x00);
|
||||||
|
I2C_writeReg(I2C_DEV_LCD_BOT, 0x60, 0x00);
|
||||||
|
wait(5);
|
||||||
|
|
||||||
|
// LCD panel (bias ?) voltage on
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 0x02);
|
||||||
|
wait(50);
|
||||||
|
|
||||||
|
// Backlight voltage on
|
||||||
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 0x28);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void zerofillN3dsAblRegisters(void)
|
||||||
|
{
|
||||||
|
invokeArm11Function(ZEROFILL_N3DS_ABL_REGISTERS);
|
||||||
|
}
|
||||||
77
arm9/source/screen.h
Normal file
77
arm9/source/screen.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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,
|
||||||
|
ZEROFILL_N3DS_ABL_REGISTERS,
|
||||||
|
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);
|
||||||
|
void zerofillN3dsAblRegisters(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, =0x4BEEF
|
||||||
|
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);
|
||||||
160
arm9/source/types.h
Normal file
160
arm9/source/types.h
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* 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 ScreenFiltersCfgData {
|
||||||
|
u16 cct;
|
||||||
|
bool invert;
|
||||||
|
u8 colorCurveCorrection;
|
||||||
|
s64 gammaEnc;
|
||||||
|
s64 contrastEnc;
|
||||||
|
s64 brightnessEnc;
|
||||||
|
} ScreenFiltersCfgData;
|
||||||
|
|
||||||
|
typedef struct CfgData {
|
||||||
|
u16 formatVersionMajor, formatVersionMinor;
|
||||||
|
|
||||||
|
u32 config, multiConfig, bootConfig;
|
||||||
|
u32 splashDurationMsec;
|
||||||
|
s8 volumeSliderOverride;
|
||||||
|
|
||||||
|
u64 hbldr3dsxTitleId;
|
||||||
|
u32 rosalinaMenuCombo;
|
||||||
|
u32 pluginLoaderFlags;
|
||||||
|
s16 ntpTzOffetMinutes;
|
||||||
|
|
||||||
|
ScreenFiltersCfgData topScreenFilter;
|
||||||
|
ScreenFiltersCfgData bottomScreenFilter;
|
||||||
|
|
||||||
|
u64 autobootTwlTitleId;
|
||||||
|
u8 autobootCtrAppmemtype;
|
||||||
|
} CfgData;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u16 lumaVersion;
|
||||||
|
u8 bootCfg;
|
||||||
|
u8 reserved[2];
|
||||||
|
u8 checksum;
|
||||||
|
} CfgDataMcu;
|
||||||
|
|
||||||
|
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,
|
||||||
|
} FirmwareSource;
|
||||||
|
|
||||||
|
typedef enum FirmwareType
|
||||||
|
{
|
||||||
|
NATIVE_FIRM = 0,
|
||||||
|
TWL_FIRM,
|
||||||
|
AGB_FIRM,
|
||||||
|
SAFE_FIRM,
|
||||||
|
SYSUPDATER_FIRM,
|
||||||
|
NATIVE_FIRM1X2X,
|
||||||
|
NATIVE_PROTOTYPE,
|
||||||
|
} FirmwareType;
|
||||||
|
|
||||||
|
typedef enum bootType
|
||||||
|
{
|
||||||
|
B9S = 0,
|
||||||
|
B9SNTR,
|
||||||
|
FIRM0,
|
||||||
|
FIRM1,
|
||||||
|
FIRMLAUNCH,
|
||||||
|
NTR
|
||||||
|
} BootType;
|
||||||
|
|
||||||
|
extern bool isSdMode;
|
||||||
|
|
||||||
|
extern BootType bootType;
|
||||||
|
|
||||||
|
extern char launchedPathForFatfs[256];
|
||||||
|
extern u16 launchedFirmTidLow[8];
|
||||||
|
extern u16 launchedPath[80+1];
|
||||||
|
|
||||||
|
extern u16 mcuFwVersion;
|
||||||
|
extern u8 mcuConsoleInfo[9];
|
||||||
251
arm9/source/utils.c
Normal file
251
arm9/source/utils.c
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2022 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"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((noreturn)) void mcuPowerOff(void)
|
||||||
|
{
|
||||||
|
// Unmount partitions
|
||||||
|
unmountPartitions();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CRC-16/MODBUS
|
||||||
|
u16 crc16(const void *data, size_t size, u16 initialValue)
|
||||||
|
{
|
||||||
|
static const u16 lut[256] = {
|
||||||
|
0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,
|
||||||
|
0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440,
|
||||||
|
0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40,
|
||||||
|
0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841,
|
||||||
|
0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40,
|
||||||
|
0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41,
|
||||||
|
0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641,
|
||||||
|
0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040,
|
||||||
|
0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240,
|
||||||
|
0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441,
|
||||||
|
0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41,
|
||||||
|
0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840,
|
||||||
|
0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41,
|
||||||
|
0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40,
|
||||||
|
0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640,
|
||||||
|
0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041,
|
||||||
|
0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240,
|
||||||
|
0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441,
|
||||||
|
0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41,
|
||||||
|
0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840,
|
||||||
|
0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41,
|
||||||
|
0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40,
|
||||||
|
0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640,
|
||||||
|
0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041,
|
||||||
|
0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241,
|
||||||
|
0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440,
|
||||||
|
0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40,
|
||||||
|
0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841,
|
||||||
|
0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40,
|
||||||
|
0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41,
|
||||||
|
0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641,
|
||||||
|
0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040,
|
||||||
|
};
|
||||||
|
|
||||||
|
u16 r = initialValue;
|
||||||
|
const u8 *data8 = (const u8 *)data;
|
||||||
|
for (size_t i = 0; i < size; i++)
|
||||||
|
r = (r >> 8) ^ lut[(r ^ data8[i]) & 0xFF];
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 crc32(const void *data, size_t size, u32 initialValue)
|
||||||
|
{
|
||||||
|
static const u32 lut[256] = {
|
||||||
|
0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,
|
||||||
|
0x0EDB8832,0x79DCB8A4,0xE0D5E91E,0x97D2D988,0x09B64C2B,0x7EB17CBD,0xE7B82D07,0x90BF1D91,
|
||||||
|
0x1DB71064,0x6AB020F2,0xF3B97148,0x84BE41DE,0x1ADAD47D,0x6DDDE4EB,0xF4D4B551,0x83D385C7,
|
||||||
|
0x136C9856,0x646BA8C0,0xFD62F97A,0x8A65C9EC,0x14015C4F,0x63066CD9,0xFA0F3D63,0x8D080DF5,
|
||||||
|
0x3B6E20C8,0x4C69105E,0xD56041E4,0xA2677172,0x3C03E4D1,0x4B04D447,0xD20D85FD,0xA50AB56B,
|
||||||
|
0x35B5A8FA,0x42B2986C,0xDBBBC9D6,0xACBCF940,0x32D86CE3,0x45DF5C75,0xDCD60DCF,0xABD13D59,
|
||||||
|
0x26D930AC,0x51DE003A,0xC8D75180,0xBFD06116,0x21B4F4B5,0x56B3C423,0xCFBA9599,0xB8BDA50F,
|
||||||
|
0x2802B89E,0x5F058808,0xC60CD9B2,0xB10BE924,0x2F6F7C87,0x58684C11,0xC1611DAB,0xB6662D3D,
|
||||||
|
0x76DC4190,0x01DB7106,0x98D220BC,0xEFD5102A,0x71B18589,0x06B6B51F,0x9FBFE4A5,0xE8B8D433,
|
||||||
|
0x7807C9A2,0x0F00F934,0x9609A88E,0xE10E9818,0x7F6A0DBB,0x086D3D2D,0x91646C97,0xE6635C01,
|
||||||
|
0x6B6B51F4,0x1C6C6162,0x856530D8,0xF262004E,0x6C0695ED,0x1B01A57B,0x8208F4C1,0xF50FC457,
|
||||||
|
0x65B0D9C6,0x12B7E950,0x8BBEB8EA,0xFCB9887C,0x62DD1DDF,0x15DA2D49,0x8CD37CF3,0xFBD44C65,
|
||||||
|
0x4DB26158,0x3AB551CE,0xA3BC0074,0xD4BB30E2,0x4ADFA541,0x3DD895D7,0xA4D1C46D,0xD3D6F4FB,
|
||||||
|
0x4369E96A,0x346ED9FC,0xAD678846,0xDA60B8D0,0x44042D73,0x33031DE5,0xAA0A4C5F,0xDD0D7CC9,
|
||||||
|
0x5005713C,0x270241AA,0xBE0B1010,0xC90C2086,0x5768B525,0x206F85B3,0xB966D409,0xCE61E49F,
|
||||||
|
0x5EDEF90E,0x29D9C998,0xB0D09822,0xC7D7A8B4,0x59B33D17,0x2EB40D81,0xB7BD5C3B,0xC0BA6CAD,
|
||||||
|
0xEDB88320,0x9ABFB3B6,0x03B6E20C,0x74B1D29A,0xEAD54739,0x9DD277AF,0x04DB2615,0x73DC1683,
|
||||||
|
0xE3630B12,0x94643B84,0x0D6D6A3E,0x7A6A5AA8,0xE40ECF0B,0x9309FF9D,0x0A00AE27,0x7D079EB1,
|
||||||
|
0xF00F9344,0x8708A3D2,0x1E01F268,0x6906C2FE,0xF762575D,0x806567CB,0x196C3671,0x6E6B06E7,
|
||||||
|
0xFED41B76,0x89D32BE0,0x10DA7A5A,0x67DD4ACC,0xF9B9DF6F,0x8EBEEFF9,0x17B7BE43,0x60B08ED5,
|
||||||
|
0xD6D6A3E8,0xA1D1937E,0x38D8C2C4,0x4FDFF252,0xD1BB67F1,0xA6BC5767,0x3FB506DD,0x48B2364B,
|
||||||
|
0xD80D2BDA,0xAF0A1B4C,0x36034AF6,0x41047A60,0xDF60EFC3,0xA867DF55,0x316E8EEF,0x4669BE79,
|
||||||
|
0xCB61B38C,0xBC66831A,0x256FD2A0,0x5268E236,0xCC0C7795,0xBB0B4703,0x220216B9,0x5505262F,
|
||||||
|
0xC5BA3BBE,0xB2BD0B28,0x2BB45A92,0x5CB36A04,0xC2D7FFA7,0xB5D0CF31,0x2CD99E8B,0x5BDEAE1D,
|
||||||
|
0x9B64C2B0,0xEC63F226,0x756AA39C,0x026D930A,0x9C0906A9,0xEB0E363F,0x72076785,0x05005713,
|
||||||
|
0x95BF4A82,0xE2B87A14,0x7BB12BAE,0x0CB61B38,0x92D28E9B,0xE5D5BE0D,0x7CDCEFB7,0x0BDBDF21,
|
||||||
|
0x86D3D2D4,0xF1D4E242,0x68DDB3F8,0x1FDA836E,0x81BE16CD,0xF6B9265B,0x6FB077E1,0x18B74777,
|
||||||
|
0x88085AE6,0xFF0F6A70,0x66063BCA,0x11010B5C,0x8F659EFF,0xF862AE69,0x616BFFD3,0x166CCF45,
|
||||||
|
0xA00AE278,0xD70DD2EE,0x4E048354,0x3903B3C2,0xA7672661,0xD06016F7,0x4969474D,0x3E6E77DB,
|
||||||
|
0xAED16A4A,0xD9D65ADC,0x40DF0B66,0x37D83BF0,0xA9BCAE53,0xDEBB9EC5,0x47B2CF7F,0x30B5FFE9,
|
||||||
|
0xBDBDF21C,0xCABAC28A,0x53B39330,0x24B4A3A6,0xBAD03605,0xCDD70693,0x54DE5729,0x23D967BF,
|
||||||
|
0xB3667A2E,0xC4614AB8,0x5D681B02,0x2A6F2B94,0xB40BBE37,0xC30C8EA1,0x5A05DF1B,0x2D02EF8D,
|
||||||
|
};
|
||||||
|
|
||||||
|
u32 r = initialValue;
|
||||||
|
const u8 *data8 = (const u8 *)data;
|
||||||
|
for (size_t i = 0; i < size; i++)
|
||||||
|
r = (r >> 8) ^ lut[(r ^ data8[i]) & 0xFF];
|
||||||
|
|
||||||
|
return ~r;
|
||||||
|
}
|
||||||
51
arm9/source/utils.h
Normal file
51
arm9/source/utils.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2016-2022 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))
|
||||||
|
|
||||||
|
void startChrono(void);
|
||||||
|
u64 chrono(void);
|
||||||
|
|
||||||
|
u32 waitInput(bool isMenu);
|
||||||
|
void mcuPowerOff(void);
|
||||||
|
void wait(u64 amount);
|
||||||
|
void error(const char *fmt, ...);
|
||||||
|
|
||||||
|
u16 crc16(const void *data, size_t size, u16 initialValue);
|
||||||
|
u32 crc32(const void *data, size_t size, u32 initialValue);
|
||||||
@ -1,50 +0,0 @@
|
|||||||
.nds
|
|
||||||
|
|
||||||
sdmmc equ 0x434D4453 ;dummy
|
|
||||||
|
|
||||||
.create "emunand.bin", 0x0801A5C0
|
|
||||||
.org 0x0801A5C0
|
|
||||||
.arm
|
|
||||||
nand_sd:
|
|
||||||
; 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, =sdmmc
|
|
||||||
cmp r2, r1
|
|
||||||
beq nand_sd_ret
|
|
||||||
|
|
||||||
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, =nand_offset
|
|
||||||
ldr r3, [r3]
|
|
||||||
add r2, r3 ; Add the offset to the NAND in the SD.
|
|
||||||
|
|
||||||
ldreq r3, =ncsd_header_offset
|
|
||||||
ldreq r3, [r3]
|
|
||||||
addeq r2, r3 ; If we're reading the ncsd header, add the offset of that sector.
|
|
||||||
|
|
||||||
str r2, [r0, #8] ; Store sector to read
|
|
||||||
|
|
||||||
nand_sd_ret:
|
|
||||||
; 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
|
|
||||||
nand_offset: .ascii "NAND" ; for rednand this should be 1
|
|
||||||
ncsd_header_offset: .ascii "NCSD" ; depends on nand manufacturer + emunand type (GW/RED)
|
|
||||||
.close
|
|
||||||
BIN
img/boot_menu_v1321.png
Normal file
BIN
img/boot_menu_v1321.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
BIN
img/rosalina_menu_v1321.png
Normal file
BIN
img/rosalina_menu_v1321.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
145
k11_extension/Makefile
Normal file
145
k11_extension/Makefile
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.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
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# -mgeneral-regs-only so that the C code is guaranteed not to use FPU regs
|
||||||
|
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mgeneral-regs-only
|
||||||
|
DEFINES := -DARM11 -D__3DS__
|
||||||
|
|
||||||
|
FALSEPOSITIVES := -Wno-array-bounds -Wno-stringop-overflow -Wno-stringop-overread
|
||||||
|
CFLAGS := -g -std=gnu11 -Wall -Wextra -Werror -O2 -mword-relocations \
|
||||||
|
-fomit-frame-pointer -ffunction-sections -fdata-sections \
|
||||||
|
-Wno-main $(FALSEPOSITIVES) $(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
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
40
k11_extension/include/config.h
Normal file
40
k11_extension/include/config.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#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, 1)
|
||||||
|
#define BOOTCFG_EMUINDEX BOOTCONFIG(1, 3)
|
||||||
|
#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(3, 1)
|
||||||
|
#define BOOTCFG_NTRCARDBOOT BOOTCONFIG(4, 1)
|
||||||
|
|
||||||
|
enum multiOptions
|
||||||
|
{
|
||||||
|
DEFAULTEMU = 0,
|
||||||
|
BRIGHTNESS,
|
||||||
|
SPLASH,
|
||||||
|
PIN,
|
||||||
|
NEWCPU,
|
||||||
|
AUTOBOOTMODE,
|
||||||
|
FORCEAUDIOOUTPUT,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum singleOptions
|
||||||
|
{
|
||||||
|
AUTOBOOTEMU = 0,
|
||||||
|
LOADEXTFIRMSANDMODULES,
|
||||||
|
PATCHGAMES,
|
||||||
|
REDIRECTAPPTHREADS,
|
||||||
|
PATCHVERSTRING,
|
||||||
|
SHOWGBABOOT,
|
||||||
|
PATCHUNITINFO,
|
||||||
|
ENABLEDSIEXTFILTER,
|
||||||
|
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;
|
||||||
192
k11_extension/include/globals.h
Normal file
192
k11_extension/include/globals.h
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* 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 KObjectList *resourceLimitList;
|
||||||
|
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__QueryMemory)(KProcessHwInfo *this, MemoryInfo *memoryInfo, PageInfo *pageInfo, void *address);
|
||||||
|
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 (*KProcessHwInfo__CheckVaState)(KProcessHwInfo *hwInfo, u32 va, u32 size, u32 state, u32 perm);
|
||||||
|
extern Result (*KProcessHwInfo__GetListOfKBlockInfoForVA)(KProcessHwInfo *hwInfo, KLinkedList *list, u32 va, u32 sizeInPage);
|
||||||
|
extern Result (*KProcessHwInfo__MapListOfKBlockInfo)(KProcessHwInfo *this, u32 va, KLinkedList *list, u32 state, u32 perm, u32 sbz);
|
||||||
|
extern Result (*KEvent__Clear)(KEvent *this);
|
||||||
|
extern Result (*KEvent__Signal)(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 void (*KLinkedList_KBlockInfo__Clear)(KLinkedList *list);
|
||||||
|
|
||||||
|
extern Result (*ControlMemory)(u32 *addrOut, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm, bool isLoader);
|
||||||
|
extern Result (*doControlMemory)(KProcessHwInfo *this, u32 addr, u32 requestedNbPages, u32 pa, u32 state, u32 perm, u32 a7, u32 region);
|
||||||
|
extern Result (*CreateThread)(Handle *outThreadHandle, u32 ep, u32 arg, u32 stackTop, s32 priority, s32 processorId);
|
||||||
|
extern void (*SleepThread)(s64 ns);
|
||||||
|
extern Result (*CreateEvent)(Handle *out, ResetType resetType);
|
||||||
|
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 (*SignalEvent)(Handle event);
|
||||||
|
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 FcramDescriptor *fcramDescriptor;
|
||||||
|
|
||||||
|
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);
|
||||||
|
extern void* (*kAlloc)(FcramDescriptor *fcramDesc, u32 nbPages, u32 alignment, u32 region);
|
||||||
|
|
||||||
|
typedef struct ScreenFiltersCfgData {
|
||||||
|
u16 cct;
|
||||||
|
bool invert;
|
||||||
|
u8 colorCurveCorrection;
|
||||||
|
s64 gammaEnc;
|
||||||
|
s64 contrastEnc;
|
||||||
|
s64 brightnessEnc;
|
||||||
|
} ScreenFiltersCfgData;
|
||||||
|
|
||||||
|
typedef struct CfwInfo
|
||||||
|
{
|
||||||
|
char magic[4];
|
||||||
|
|
||||||
|
u8 versionMajor;
|
||||||
|
u8 versionMinor;
|
||||||
|
u8 versionBuild;
|
||||||
|
u8 flags;
|
||||||
|
|
||||||
|
u32 commitHash;
|
||||||
|
|
||||||
|
u16 configFormatVersionMajor, configFormatVersionMinor;
|
||||||
|
u32 config, multiConfig, bootConfig;
|
||||||
|
u32 splashDurationMsec;
|
||||||
|
s8 volumeSliderOverride;
|
||||||
|
u64 hbldr3dsxTitleId;
|
||||||
|
u32 rosalinaMenuCombo;
|
||||||
|
u32 pluginLoaderFlags;
|
||||||
|
s16 ntpTzOffetMinutes;
|
||||||
|
|
||||||
|
ScreenFiltersCfgData topScreenFilter;
|
||||||
|
ScreenFiltersCfgData bottomScreenFilter;
|
||||||
|
|
||||||
|
u64 autobootTwlTitleId;
|
||||||
|
u8 autobootCtrAppmemtype;
|
||||||
|
|
||||||
|
u16 launchedPath[80+1];
|
||||||
|
} CfwInfo;
|
||||||
|
|
||||||
|
extern CfwInfo cfwInfo;
|
||||||
|
extern u32 kextBasePa;
|
||||||
|
extern u32 stolenSystemMemRegionSize;
|
||||||
|
extern bool disableThreadRedirection;
|
||||||
|
|
||||||
|
extern vu32 rosalinaState;
|
||||||
|
extern bool hasStartedRosalinaNetworkFuncsOnce;
|
||||||
|
extern KEvent* signalPluginEvent;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
PLG_CFG_NONE = 0,
|
||||||
|
PLG_CFG_RUNNING = 1,
|
||||||
|
PLG_CFG_INHOME = 2,
|
||||||
|
PLG_CFG_EXITING = 3,
|
||||||
|
|
||||||
|
PLG_CFG_HOME_EVENT = 1 << 16,
|
||||||
|
PLG_CFG_EXIT_EVENT = 2 << 16
|
||||||
|
} PLG_CFG_STATUS;
|
||||||
|
|
||||||
|
void PLG_SignalEvent(u32 event);
|
||||||
|
void PLG__WakeAppThread(void);
|
||||||
|
u32 PLG_GetStatus(void);
|
||||||
|
KLinkedList* KLinkedList__Initialize(KLinkedList *list);
|
||||||
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);
|
||||||
1325
k11_extension/include/kernel.h
Normal file
1325
k11_extension/include/kernel.h
Normal file
File diff suppressed because it is too large
Load Diff
129
k11_extension/include/mmu.h
Normal file
129
k11_extension/include/mmu.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 bits1_0 : 2; ///< 0b00
|
||||||
|
} Desc_TranslationFault;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 bits1_0 : 2; ///< 0b01
|
||||||
|
u32 sbz : 3;
|
||||||
|
u32 domain : 4;
|
||||||
|
u32 p : 1;
|
||||||
|
u32 addr : 21;
|
||||||
|
} Desc_CoarsePageTable;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 bits1_0 : 2; ///< 0b10
|
||||||
|
u32 b : 1;
|
||||||
|
u32 c : 1;
|
||||||
|
u32 xn : 1;
|
||||||
|
u32 domain : 4;
|
||||||
|
u32 p : 1;
|
||||||
|
u32 ap : 2;
|
||||||
|
u32 tex : 3;
|
||||||
|
u32 apx : 1;
|
||||||
|
u32 s : 1;
|
||||||
|
u32 ng : 1;
|
||||||
|
u32 bit18 : 1; ///< 0
|
||||||
|
u32 sbz : 1;
|
||||||
|
u32 addr : 12;
|
||||||
|
} Desc_Section;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 bits1_0 : 2; ///< 0b10
|
||||||
|
u32 b : 1;
|
||||||
|
u32 c : 1;
|
||||||
|
u32 xn : 1;
|
||||||
|
u32 domain : 4;
|
||||||
|
u32 p : 1;
|
||||||
|
u32 ap : 2;
|
||||||
|
u32 tex : 3;
|
||||||
|
u32 sbz : 3;
|
||||||
|
u32 bit18 : 1; ///< 1
|
||||||
|
u32 sbz2 : 5;
|
||||||
|
u32 addr : 8;
|
||||||
|
} Desc_Supersection;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 bits1_0 : 2; ///< 0b11
|
||||||
|
} Desc_Reserved;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 bits1_0 : 2; ///< 0b01
|
||||||
|
u32 b : 1;
|
||||||
|
u32 c : 1;
|
||||||
|
u32 ap : 2;
|
||||||
|
u32 sbz : 3;
|
||||||
|
u32 apx : 1;
|
||||||
|
u32 s : 1;
|
||||||
|
u32 ng : 1;
|
||||||
|
u32 tex : 3;
|
||||||
|
u32 xn : 1;
|
||||||
|
u32 addr : 16;
|
||||||
|
} Desc_LargePage;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 xn : 1;
|
||||||
|
u32 bit1 : 1; ///< 1
|
||||||
|
u32 b : 1;
|
||||||
|
u32 c : 1;
|
||||||
|
u32 ap : 2;
|
||||||
|
u32 tex : 3;
|
||||||
|
u32 apx : 1;
|
||||||
|
u32 s : 1;
|
||||||
|
u32 ng : 1;
|
||||||
|
u32 addr : 20;
|
||||||
|
} Desc_SmallPage;
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
u32 raw;
|
||||||
|
|
||||||
|
Desc_TranslationFault translationFault;
|
||||||
|
Desc_CoarsePageTable coarsePageTable;
|
||||||
|
Desc_Section section;
|
||||||
|
Desc_Supersection supersection;
|
||||||
|
Desc_Reserved reserved;
|
||||||
|
|
||||||
|
} L1Descriptor;
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
u32 raw;
|
||||||
|
|
||||||
|
Desc_TranslationFault translationFault;
|
||||||
|
Desc_LargePage largePage;
|
||||||
|
Desc_SmallPage smallPage;
|
||||||
|
} L2Descriptor;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
Descriptor_TranslationFault,
|
||||||
|
Descriptor_CoarsePageTable,
|
||||||
|
Descriptor_Section,
|
||||||
|
Descriptor_Supersection,
|
||||||
|
Descriptor_Reserved,
|
||||||
|
Descriptor_LargePage,
|
||||||
|
Descriptor_SmallPage
|
||||||
|
} DescType;
|
||||||
|
|
||||||
|
void L1MMUTable__RWXForAll(u32 *table);
|
||||||
|
void L2MMUTable__RWXForAll(u32 *table);
|
||||||
|
u32 L1MMUTable__GetPAFromVA(u32 *table, u32 va);
|
||||||
|
u32 L2MMUTable__GetPAFromVA(u32 *table, u32 va);
|
||||||
|
u32 L1MMUTable__GetAddressUserPerm(u32 *table, u32 va);
|
||||||
|
u32 L2MMUTable__GetAddressUserPerm(u32 *table, u32 va);
|
||||||
|
|
||||||
|
void KProcessHwInfo__SetMMUTableToRWX(KProcessHwInfo *hwInfo);
|
||||||
|
u32 KProcessHwInfo__GetPAFromVA(KProcessHwInfo *hwInfo, u32 va);
|
||||||
|
u32 KProcessHwInfo__GetAddressUserPerm(KProcessHwInfo *hwInfo, u32 va);
|
||||||
40
k11_extension/include/svc.h
Normal file
40
k11_extension/include/svc.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "globals.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
extern void *officialSVCs[0x7E];
|
||||||
|
extern void *alteredSvcTable[0x100];
|
||||||
|
|
||||||
|
void buildAlteredSvcTable(void);
|
||||||
|
|
||||||
|
void postprocessSvc(void);
|
||||||
|
void svcDefaultHandler(u8 svcId);
|
||||||
33
k11_extension/include/svc/Backdoor.h
Normal file
33
k11_extension/include/svc/Backdoor.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 "utils.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
#include "svc.h"
|
||||||
|
|
||||||
|
void Backdoor(void *function);
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user