This source file includes following definitions.
- log_fwt_msg
- log_fwt_start
- filewritetask
- sub_FF3970B0_my
- sub_FF397958_my
- sub_FF397288_my
1
2
3
4 #include "lolevel.h"
5 #include "platform.h"
6
7 #ifdef CAM_HAS_FILEWRITETASK_HOOK
8
9 #define FILEWRITE_DEBUG_LOG 1
10 extern void _LogCameraEvent(int id,const char *fmt,...);
11
12 typedef struct {
13 unsigned int address;
14 unsigned int length;
15 } cam_ptp_data_chunk;
16
17 #define MAX_CHUNKS_FOR_FWT 7
18
19
20
21
22
23
24
25
26
27
28 typedef struct
29 {
30 int unkn1;
31 int file_offset;
32 int maybe_full_size;
33 int unkn2, unkn3;
34 int unkn4;
35 cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_FWT];
36 int maybe_seek_flag;
37 int unkn5, unkn6;
38 char name[32];
39 } fwt_data_struct;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 #include "../../../generic/filewrite.c"
57
58 #ifdef FILEWRITE_DEBUG_LOG
59 void log_fwt_msg(fwt_data_struct *fwd)
60 {
61 int m=fwd->unkn1;
62 _LogCameraEvent(0x60,"fw m:%d o:0x%08x fs:0x%08x sf:0x%x",m,fwd->file_offset,fwd->maybe_full_size,fwd->maybe_seek_flag);
63 _LogCameraEvent(0x60,"fw %s",fwd->name);
64 if(m >= 0 && m <=6) {
65 _LogCameraEvent(0x60,"fw chunk adr:0x%08x l:0x%08x",fwd->pdc[m].address,fwd->pdc[m].length);
66 }
67 _LogCameraEvent(0x60,"fw u %08x %08x %08x %08x %08x %08x",fwd->unkn2,fwd->unkn3,fwd->unkn4,fwd->unkn5,fwd->unkn6);
68 }
69
70 void log_fwt_start(void)
71 {
72 _LogCameraEvent(0x60,"fw start");
73 }
74 #endif
75
76
77
78
79 void __attribute__((naked,noinline)) filewritetask() {
80 asm volatile (
81 " STMFD SP!, {R1-R5,LR} \n"
82 #ifdef FILEWRITE_DEBUG_LOG
83 "bl log_fwt_start\n"
84 #endif
85 " LDR R5, =0xF2C4 \n"
86
87 "loc_FF397490:\n"
88 " MOV R2, #0 \n"
89 " LDR R0, [R5, #0x14] \n"
90 " ADD R1, SP, #8 \n"
91 " BL sub_006B8490 /*_ReceiveMessageQueue*/ \n"
92 " CMP R0, #0 \n"
93 " LDRNE R2, =0x477 \n"
94 " LDRNE R1, =0xFF3975FC /*'dwFWrite.c'*/ \n"
95 " MOVNE R0, #0 \n"
96 " BLNE _DebugAssert \n"
97 #ifdef FILEWRITE_DEBUG_LOG
98 "ldr r0, [sp,#8]\n"
99 "bl log_fwt_msg\n"
100 #endif
101 " LDR R0, [SP, #8] \n"
102 " LDR R1, [R0] \n"
103 " CMP R1, #0xD \n"
104 " ADDCC PC, PC, R1, LSL#2 \n"
105 " B loc_FF397490 \n"
106 " B loc_FF3975BC \n"
107 " B loc_FF3975BC \n"
108 " B loc_FF3975BC \n"
109 " B loc_FF3975BC \n"
110 " B loc_FF3975BC \n"
111 " B loc_FF3975BC \n"
112 " B loc_FF3975BC \n"
113 " B loc_FF3975C4 \n"
114 " B loc_FF3974FC \n"
115 " B loc_FF397584 \n"
116 " B loc_FF3975B4 \n"
117 " B loc_FF397574 \n"
118 " B loc_FF39757C \n"
119
120 "loc_FF3974FC:\n"
121 " MOV R0, #0 \n"
122 " STR R0, [SP] \n"
123
124 "loc_FF397504:\n"
125 " LDR R0, [R5, #0x14] \n"
126 " MOV R1, SP \n"
127 " BL sub_006B870C /*_GetNumberOfPostedMessages*/ \n"
128 " LDR R0, [SP] \n"
129 " CMP R0, #0 \n"
130 " BEQ loc_FF397530 \n"
131 " LDR R0, [R5, #0x14] \n"
132 " MOV R2, #0 \n"
133 " ADD R1, SP, #4 \n"
134 " BL sub_006B8490 /*_ReceiveMessageQueue*/ \n"
135 " B loc_FF397504 \n"
136
137 "loc_FF397530:\n"
138 " LDR R0, [R5, #8] \n"
139 " MOV R4, R5 \n"
140 " CMN R0, #1 \n"
141 " BEQ loc_FF397568 \n"
142 " BL _Close \n"
143 " MVN R0, #0 \n"
144 " STR R0, [R4, #8] \n"
145 " MOV R1, #0 \n"
146 " MOV R0, #0x48 \n"
147 " BL sub_FF0C61D0 \n"
148 " LDR R0, =0x18E4E4 \n"
149 " BL sub_FF030C9C \n"
150 " MOV R1, #0 \n"
151 " BL sub_FF02EB58 \n"
152
153 "loc_FF397568:\n"
154 " LDR R0, [R4, #0x10] \n"
155 " BL _GiveSemaphore \n"
156 " B loc_FF397490 \n"
157
158 "loc_FF397574:\n"
159 " BL sub_FF39781C \n"
160 " B loc_FF397490 \n"
161
162 "loc_FF39757C:\n"
163 " BL sub_FF3970B0_my \n"
164 " B loc_FF397490 \n"
165
166 "loc_FF397584:\n"
167 " LDR R1, [R0, #4] \n"
168 " MOV R4, R0 \n"
169 " LDR R0, [R5, #8] \n"
170 " MOV R2, #0 \n"
171 " BL _lseek \n"
172 " CMN R0, #1 \n"
173 " LDREQ R0, =0x9200013 \n"
174 " MOVEQ R1, R4 \n"
175 " STREQ R0, [R4, #0x14] \n"
176 " MOVEQ R0, #7 \n"
177 " BLEQ sub_FF396FE8 \n"
178 " B loc_FF397490 \n"
179
180 "loc_FF3975B4:\n"
181 " BL sub_FF3978BC \n"
182 " B loc_FF397490 \n"
183
184 "loc_FF3975BC:\n"
185 " BL sub_FF397958_my \n"
186 " B loc_FF397490 \n"
187
188 "loc_FF3975C4:\n"
189 " BL sub_FF397288_my \n"
190 " B loc_FF397490 \n"
191 );
192 }
193
194
195
196 void __attribute__((naked,noinline)) sub_FF3970B0_my() {
197 asm volatile (
198 " STMFD SP!, {R4-R9,LR} \n"
199 " MOV R4, R0 \n"
200
201
202 " BL filewrite_main_hook\n"
203 " MOV R0, R4\n"
204 " LDR R0, [R0, #0x50] \n"
205 " LDR R7, =0xF2C4 \n"
206 " TST R0, #5 \n"
207 " SUB SP, SP, #0x3C \n"
208 " BEQ loc_FF3970F4 \n"
209 " LDR R0, [R7, #0x1C] \n"
210 " CMP R0, #0 \n"
211 " BLXNE R0 \n"
212 " ADD R0, R4, #0x5C \n"
213 " BL sub_FF030C9C \n"
214 " MOV R1, #0 \n"
215 " BL sub_FF02EA18 \n"
216 " MOV R1, #0 \n"
217 " MOV R0, #0x47 \n"
218 " BL sub_FF0C61D0 \n"
219
220 "loc_FF3970F4:\n"
221 " LDR R0, [R4, #0x50] \n"
222 " TST R0, #1 \n"
223 " BEQ loc_FF397258 \n"
224 " LDR R0, [R4, #0x10] \n"
225 " BL sub_FF02D8BC \n"
226 " LDR R0, [R4, #0x50] \n"
227 " LDR R5, =0x301 \n"
228 " TST R0, #0x10 \n"
229 " MOVNE R5, #9 \n"
230 " BNE loc_FF397124 \n"
231 " TST R0, #0x40 \n"
232 " MOVNE R5, #1 \n"
233
234 "loc_FF397124:\n"
235 " TST R0, #0x20 \n"
236 " BNE loc_FF397138 \n"
237 " LDR R0, [R4, #0x58] \n"
238 " CMP R0, #1 \n"
239 " BNE loc_FF39713C \n"
240
241 "loc_FF397138:\n"
242 " ORR R5, R5, #0x8000 \n"
243
244 "loc_FF39713C:\n"
245 " LDR R9, =0x1B6 \n"
246 " ADD R8, R4, #0x5C \n"
247 " LDR R6, [R4, #0x10] \n"
248 " MOV R2, R9 \n"
249 " MOV R1, R5 \n"
250 " MOV R0, R8 \n"
251 " BL fwt_open \n"
252 " CMN R0, #1 \n"
253 " BNE loc_FF3971BC \n"
254 " MOV R0, R8 \n"
255 " BL sub_FF027684 \n"
256 " MOV R2, #0xF \n"
257 " MOV R1, R8 \n"
258 " ADD R0, SP, #4 \n"
259 " BL sub_006DAA10 \n"
260 " MOV R0, #0 \n"
261 " LDR R1, =0x41FF \n"
262 " STRB R0, [SP, #0x13] \n"
263 " STR R1, [SP, #0x24] \n"
264 " MOV R1, #0x10 \n"
265 " STR R0, [SP, #0x2C] \n"
266 " STR R1, [SP, #0x28] \n"
267 " ADD R1, SP, #0x24 \n"
268 " ADD R0, SP, #4 \n"
269 " STR R6, [SP, #0x30] \n"
270 " STR R6, [SP, #0x34] \n"
271 " STR R6, [SP, #0x38] \n"
272 " BL sub_FF02E37C \n"
273 " MOV R2, R9 \n"
274 " MOV R1, R5 \n"
275 " MOV R0, R8 \n"
276 " BL _Open \n"
277
278 "loc_FF3971BC:\n"
279 " CMN R0, #1 \n"
280 " MOV R5, R0 \n"
281 " STR R0, [R7, #8] \n"
282 " BNE loc_FF397218 \n"
283 " MOV R1, #0 \n"
284 " MOV R0, #0x48 \n"
285 " BL sub_FF0C61D0 \n"
286 " ADD R0, R4, #0x5C \n"
287 " BL sub_FF030C9C \n"
288 " LDR R1, [R7, #0x20] \n"
289 " BL sub_FF02EB58 \n"
290 " LDR R0, [R7, #0x18] \n"
291 " CMP R0, #0 \n"
292 " BEQ loc_FF397280 \n"
293 " LDR R5, =0x9200001 \n"
294 " MOV R0, R4 \n"
295 " MOV R1, R5 \n"
296 " BL sub_FF396F84 \n"
297 " LDR R1, [R7, #0x18] \n"
298 " MOV R0, R5 \n"
299 " ADD SP, SP, #0x3C \n"
300 " LDMFD SP!, {R4-R9,LR} \n"
301 " BX R1 \n"
302
303 "loc_FF397218:\n"
304 " LDR R0, =0x18E4E4 \n"
305 " MOV R2, #0x20 \n"
306 " ADD R1, R4, #0x5C \n"
307 " BL sub_006DABF8 \n"
308 " LDR R3, =current_write_ignored\n"
309 " LDR R3, [R3]\n"
310 " CMP R3, #0\n"
311 " BNE loc_C\n"
312 " LDR R0, [R4, #0x50] \n"
313 " TST R0, #0x80 \n"
314 " BEQ loc_FF397258 \n"
315 " LDR R1, [R4, #0xC] \n"
316 " MOV R0, R5 \n"
317 " BL sub_FF027354 \n"
318 " CMP R0, #0 \n"
319 " LDREQ R0, =0x9200017 \n"
320 " MOVEQ R1, R4 \n"
321 " STREQ R0, [R4, #0x14] \n"
322 " MOVEQ R0, #7 \n"
323 " BEQ loc_FF39727C \n"
324
325 "loc_FF397258:\n"
326 "loc_C:\n"
327 " LDR R0, [R4, #0x50] \n"
328 " TST R0, #0x40 \n"
329 " LDREQ R0, [R4, #4] \n"
330 " CMPEQ R0, #0 \n"
331 " MOVNE R1, R4 \n"
332 " MOVNE R0, #9 \n"
333 " BLNE sub_FF396FE8 \n"
334 " MOV R1, R4 \n"
335 " MOV R0, #0 \n"
336
337 "loc_FF39727C:\n"
338 " BL sub_FF396FE8 \n"
339
340 "loc_FF397280:\n"
341 " ADD SP, SP, #0x3C \n"
342 " LDMFD SP!, {R4-R9,PC} \n"
343 );
344 }
345
346
347
348 void __attribute__((naked,noinline)) sub_FF397958_my() {
349 asm volatile (
350 " STMFD SP!, {R4-R10,LR} \n"
351 " MOV R5, R0 \n"
352 " LDR R0, [R0] \n"
353 " CMP R0, #6 \n"
354 " BHI loc_FF397984 \n"
355 " ADD R0, R5, R0, LSL#3 \n"
356 " LDR R8, [R0, #0x18]! \n"
357 " LDR R7, [R0, #4] \n"
358 " CMP R7, #0 \n"
359 " BNE loc_FF3979A0 \n"
360 " B loc_FF397994 \n"
361
362 "loc_FF397984:\n"
363 " MOV R2, #0x3B4 \n"
364 " LDR R1, =0xFF3975FC /*'dwFWrite.c'*/ \n"
365 " MOV R0, #0 \n"
366 " BL _DebugAssert \n"
367
368 "loc_FF397994:\n"
369 " MOV R1, R5 \n"
370 " MOV R0, #7 \n"
371 " B loc_FF397A38 \n"
372
373 "loc_FF3979A0:\n"
374 " LDR R9, =0xF2C4 \n"
375 " MOV R4, R7 \n"
376
377 "loc_FF3979A8:\n"
378 " LDR R0, [R5, #4] \n"
379 " CMP R4, #0x1000000 \n"
380 " MOVLS R6, R4 \n"
381 " MOVHI R6, #0x1000000 \n"
382 " BIC R1, R0, #0xFF000000 \n"
383 " CMP R1, #0 \n"
384 " BICNE R0, R0, #0xFF000000 \n"
385 " RSBNE R0, R0, #0x1000000 \n"
386 " CMPNE R6, R0 \n"
387 " MOVHI R6, R0 \n"
388 " LDR R0, [R9, #8] \n"
389 " MOV R2, R6 \n"
390 " MOV R1, R8 \n"
391 " BL fwt_write \n"
392 " LDR R1, [R5, #4] \n"
393 " CMP R6, R0 \n"
394 " ADD R1, R1, R0 \n"
395 " STR R1, [R5, #4] \n"
396 " BEQ loc_FF397A08 \n"
397 " CMN R0, #1 \n"
398 " LDRNE R0, =0x9200015 \n"
399 " LDREQ R0, =0x9200005 \n"
400 " STR R0, [R5, #0x14] \n"
401 " B loc_FF397994 \n"
402
403 "loc_FF397A08:\n"
404 " SUB R4, R4, R0 \n"
405 " CMP R4, R7 \n"
406 " LDRCS R2, =0x3DE \n"
407 " LDRCS R1, =0xFF3975FC /*'dwFWrite.c'*/ \n"
408 " ADD R8, R8, R0 \n"
409 " MOVCS R0, #0 \n"
410 " BLCS _DebugAssert \n"
411 " CMP R4, #0 \n"
412 " BNE loc_FF3979A8 \n"
413 " LDR R0, [R5] \n"
414 " MOV R1, R5 \n"
415 " ADD R0, R0, #1 \n"
416
417 "loc_FF397A38:\n"
418 " LDMFD SP!, {R4-R10,LR} \n"
419 " B sub_FF396FE8 \n"
420 );
421 }
422
423
424
425 void __attribute__((naked,noinline)) sub_FF397288_my() {
426 asm volatile (
427 " STMFD SP!, {R4-R6,LR} \n"
428 " MOV R4, R0 \n"
429 " LDR R0, [R0, #0x50] \n"
430 " LDR R5, =0xF2C4 \n"
431 " TST R0, #0xA \n"
432 " SUB SP, SP, #0x38 \n"
433 " BEQ sub_FF397454 \n"
434 " TST R0, #2 \n"
435 " BEQ sub_FF397330 \n"
436 " TST R0, #0x80 \n"
437 " LDRNE R0, [R4, #0xC] \n"
438 " LDRNE R1, [R4, #8] \n"
439 " CMPNE R1, R0 \n"
440 " BEQ loc_FF3972F8 \n"
441 " LDR R0, [R5, #8] \n"
442 " BL sub_FF027354 \n"
443 " CMP R0, #0 \n"
444 " LDREQ R0, =0x9200017 \n"
445 " STREQ R0, [R4, #0x14] \n"
446 " BEQ loc_FF3972F8 \n"
447 " LDR R0, [R4, #8] \n"
448 " ADD R1, SP, #0x20 \n"
449 " STR R0, [R4, #4] \n"
450 " ADD R0, R4, #0x5C \n"
451 " BL sub_FF02E2C4 \n"
452 " CMP R0, #1 \n"
453 " LDREQ R0, [R4, #4] \n"
454 " STREQ R0, [SP, #0x28] \n"
455
456 "loc_FF3972F8:\n"
457 " LDR R0, [R5, #8] \n"
458 " CMN R0, #1 \n"
459 " BEQ sub_FF397330 \n"
460 " LDR R1, [R4, #0x58] \n"
461 " LDR R6, =0x9200003 \n"
462 " CMP R1, #1 \n"
463 " BNE loc_FF39731C \n"
464 " LDR R3, =current_write_ignored\n"
465 " LDR R3, [R3]\n"
466 " CMP R3, #0\n"
467 " BNE loc_D\n"
468 " BL sub_FF0270A8 \n"
469 " B sub_FF397320 \n"
470
471 "loc_FF39731C:\n"
472 "loc_D:\n"
473 " BL fwt_close \n"
474 " LDR PC, =0xFF397320 \n"
475 );
476 }
477 #endif