root/platform/a810/sub/100d/filewrite.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFA52220_my
  3. sub_FFA52860_my
  4. sub_FFA5238C_my

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 
   4 typedef struct {
   5     unsigned int address;
   6     unsigned int length;
   7 } cam_ptp_data_chunk; //camera specific structure
   8 
   9 #define MAX_CHUNKS_FOR_JPEG 7 // filewritetask is prepared for this many chunks
  10 /*
  11  * fwt_data_struct: defined here as it's camera dependent
  12  * unneeded members are designated with unkn
  13  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  14  * pdc is always required
  15  * name is not currently used
  16  */
  17 typedef struct
  18 {
  19     int unkn1;
  20     int file_offset;    // needed for DryOS>=r50
  21     int full_size;      // needed for DryOS>=r50
  22     int unkn2, unkn3, unkn4;
  23     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_JPEG];
  24     int seek_flag;      // needed for DryOS>=r50
  25     char name[32];
  26 } fwt_data_struct;
  27 #define FWT_MUSTSEEK    2   // value of the masked seek_flag indicating seek is required
  28 #define FWT_SEEKMASK    0xffffffff   // masks out unneeded bits of seek_flag
  29 
  30 #include "../../../generic/filewrite.c"
  31 
  32 /*************** filewritetask ***************/
  33 
  34 void __attribute__((naked,noinline)) filewritetask(  ) { //@ 0xFFA52524
  35 asm volatile (
  36       "    STMFD   SP!, {R1-R7,LR} \n" 
  37       "    LDR     R7, =0x96B8 \n" 
  38       "    MOV     R6, #0 \n" 
  39 "loc_FFA52530:\n"
  40       "    LDR     R0, [R7, #0x14] \n" 
  41       "    MOV     R2, #0 \n" 
  42       "    ADD     R1, SP, #8 \n" 
  43       "    MOV     R5, R7 \n" 
  44       "    BL      sub_003F7218 \n" //ReceiveMessageQueue
  45       "    CMP     R0, #0 \n" 
  46       "    LDRNE   R1, =0x38E \n" 
  47       "    LDRNE   R0, =0xFFA52668 \n" // dwFWrite.c
  48       "    BLNE    sub_003F6AFC \n" //DebugAssert
  49       "    LDR     R0, [SP, #8] \n" 
  50       "    LDR     R1, [R0] \n" // state (aka msg number)
  51       "    CMP     R1, #0xB \n" 
  52       "    ADDCC   PC, PC, R1, LSL #2 \n" 
  53       "    B       loc_FFA52530 \n" 
  54       "    B       loc_FFA52638 \n" 
  55       "    B       loc_FFA52638 \n" 
  56       "    B       loc_FFA52638 \n" 
  57       "    B       loc_FFA52638 \n" 
  58       "    B       loc_FFA52638 \n" 
  59       "    B       loc_FFA52638 \n" 
  60       "    B       loc_FFA52638 \n" 
  61       "    B       loc_FFA52640 \n" 
  62       "    B       loc_FFA52594 \n" 
  63       "    B       loc_FFA52604 \n" 
  64       "    B       loc_FFA525FC \n" 
  65 "loc_FFA52594:\n"                   // (state 8) empties the message queue
  66       "    STR     R6, [SP] \n" 
  67 "loc_FFA52598:\n"
  68       "    LDR     R0, [R5, #0x14] \n" 
  69       "    MOV     R1, SP \n" 
  70       "    BL      sub_003F745C \n" //GetNumberOfPostedMessages
  71       "    LDR     R0, [SP] \n" 
  72       "    CMP     R0, #0 \n" 
  73       "    BEQ     loc_FFA525C4 \n" // no message left in queue
  74       "    LDR     R0, [R5, #0x14] \n" 
  75       "    MOV     R2, #0 \n" 
  76       "    ADD     R1, SP, #4 \n" 
  77       "    BL      sub_003F7218 \n" //ReceiveMessageQueue
  78       "    B       loc_FFA52598 \n" 
  79 "loc_FFA525C4:\n"
  80       "    LDR     R0, [R5, #8] \n" // file descriptor
  81       "    CMN     R0, #1 \n" 
  82       "    BEQ     loc_FFA525F0 \n" 
  83       "    BL      fwt_close\n"     // mod! sub_FF830158 Close
  84 "loc_FFA525D4:\n"
  85       "    MVN     R0, #0 \n" 
  86       "    STR     R0, [R5, #8] \n" // file descriptor
  87       "    LDR     R0, =0x132120 \n" 
  88       "    STR     R6, [R5, #4] \n" 
  89       "    BL      sub_FF86671C \n" // path check or something
  90       "    MOV     R1, #0 \n" 
  91       "    BL      sub_FF8647B8 \n" // file semaphore related
  92 "loc_FFA525F0:\n"
  93       "    LDR     R0, [R5, #0x10] \n" 
  94       "    BL      sub_003F7704 \n" //GiveSemaphore
  95       "    B       loc_FFA52530 \n" 
  96 "loc_FFA525FC:\n"
  97       "    BL      sub_FFA52220_my \n" // -> open stage (state 10)
  98       "    B       loc_FFA52530 \n" 
  99 "loc_FFA52604:\n"                   // (state 9), append? overwrite?
 100       "    LDR     R1, [R0, #4] \n" // seek offset
 101       "    MOV     R4, R0 \n" 
 102       "    LDR     R0, [R5, #8] \n" // file descriptor
 103       "    MOV     R2, #0 \n"       // SEEK_SET
 104       "    BL      fwt_lseek\n"     // mod! sub_FF8302F0  Lseek
 105       "    CMN     R0, #1 \n" 
 106       "    LDREQ   R0, =0x9200013 \n" 
 107       "    MOV     R1, R4 \n" 
 108       "    STREQ   R0, [R4, #0x14] \n" 
 109       "    MOVNE   R0, #0 \n"       // next state = 0 (write)
 110       "    MOVEQ   R0, #7 \n"       // next state = 7 (close)
 111       "    BL      sub_FFA52164 \n" // send_msg_to_filewritetask
 112       "    B       loc_FFA52530 \n" 
 113 "loc_FFA52638:\n"
 114       "    BL      sub_FFA52860_my \n" // -> write stage (states 0..6)
 115       "    B       loc_FFA52530 \n" 
 116 "loc_FFA52640:\n"
 117       "    BL      sub_FFA5238C_my \n" // -> close stage (state 7)
 118       "    B       loc_FFA52530 \n"
 119       );
 120 }
 121 
 122 
 123 void __attribute__((naked,noinline)) sub_FFA52220_my(  ) { //open
 124 asm volatile (
 125       "    STMFD   SP!, {R4-R9,LR} \n" 
 126       "    LDR     R6, =0x96B8 \n" 
 127       "    MOV     R4, R0 \n" 
 128 //hook start placed here to avoid bne a few instructions below
 129       "STMFD SP!, {R4-R12,LR}\n"
 130       //"MOV R0, R4\n"        //data block start, commented out as R0 is already holding what we need
 131       "BL filewrite_main_hook\n"
 132       "LDMFD SP!, {R4-R12,LR}\n"
 133 //hook end
 134       "    LDR     R0, [R6, #4] \n" 
 135       "    SUB     SP, SP, #0x3C \n" 
 136       "    CMP     R0, #0 \n" 
 137       "    BNE     loc_FFA5235C \n"
 138       "    ADD     R0, R4, #0x54 \n" 
 139       "    BL      sub_FF86671C \n"   // path check or something
 140       "    MOV     R1, #0 \n" 
 141       "    BL      sub_FF86472C \n" 
 142       "    LDR     R0, [R4, #0x10] \n" 
 143       "    BL      sub_FF8636F0 \n" 
 144       "    LDR     R0, [R4, #0x50] \n" 
 145       "    LDR     R9, =0x1B6 \n" 
 146       "    CMP     R0, #1 \n" 
 147       "    LDREQ   R0, [R4, #0xC] \n" 
 148       "    ADD     R7, R4, #0x54 \n" 
 149       "    ORREQ   R0, R0, #0x8000 \n" 
 150       "    STREQ   R0, [R4, #0xC] \n" 
 151       "    LDR     R8, [R4, #0xC] \n" 
 152       "    LDR     R5, [R4, #0x10] \n" 
 153       "    MOV     R2, R9 \n" 
 154       "    MOV     R1, R8 \n" 
 155       "    MOV     R0, R7 \n" 
 156       "    BL      fwt_open\n"  //mod! sub_FF830154 Open
 157       "    CMN     R0, #1 \n" // rom:ffa52288
 158       "    BNE     loc_FFA522EC \n"
 159       "    MOV     R0, R7 \n" 
 160       "    BL      sub_FF83083C \n" 
 161       "    MOV     R2, #0xF \n" 
 162       "    MOV     R1, R7 \n" 
 163       "    ADD     R0, SP, #4 \n" 
 164       "    BL      sub_003FC17C \n" 
 165       "    MOV     R0, #0 \n" 
 166       "    LDR     R1, =0x41FF \n" 
 167       "    STRB    R0, [SP, #0x13] \n" 
 168       "    STR     R1, [SP, #0x24] \n" 
 169       "    MOV     R1, #0x10 \n" 
 170       "    STR     R0, [SP, #0x2C] \n" 
 171       "    STR     R1, [SP, #0x28] \n" 
 172       "    ADD     R1, SP, #0x24 \n" 
 173       "    ADD     R0, SP, #4 \n" 
 174       "    STR     R5, [SP, #0x30] \n" 
 175       "    STR     R5, [SP, #0x34] \n" 
 176       "    STR     R5, [SP, #0x38] \n" 
 177       "    BL      sub_FF863FF8 \n" 
 178       "    MOV     R2, R9 \n" 
 179       "    MOV     R1, R8 \n" 
 180       "    MOV     R0, R7 \n" 
 181       "    BL      sub_FF830154 \n" //Open
 182 "loc_FFA522EC:\n"
 183       "    CMN     R0, #1 \n" 
 184       "    MOV     R5, R0 \n" 
 185       "    STR     R0, [R6, #8] \n" 
 186       "    BNE     loc_FFA52328 \n" 
 187       "    ADD     R0, R4, #0x54 \n" 
 188       "    BL      sub_FF86671C \n" // path check or something
 189       "    LDR     R1, [R6, #0x1C] \n" 
 190       "    BL      sub_FF8647B8 \n" 
 191       "    LDR     R1, [R6, #0x18] \n" 
 192       "    CMP     R1, #0 \n" 
 193       "    BEQ     loc_FFA52384 \n" 
 194       "    ADD     SP, SP, #0x3C \n" 
 195       "    LDMFD   SP!, {R4-R9,LR} \n" 
 196       "    LDR     R0, =0x9200001 \n" 
 197       "    BX      R1 \n" 
 198 "loc_FFA52328:\n"
 199       "    MOV     R0, #1 \n" 
 200       "    STR     R0, [R6, #4] \n" 
 201       "    LDR     R0, =0x132120 \n" 
 202       "    MOV     R2, #0x20 \n" 
 203       "    ADD     R1, R4, #0x54 \n" 
 204       "    BL      sub_003FC364 \n" 
 205 //mod start      
 206       "LDR R3, =current_write_ignored\n"
 207       "LDR R3, [R3]\n"
 208       "CMP R3, #0\n"
 209       "BNE loc_FFA5235C\n" // jump over the next block
 210 //mod end
 211       "    LDR     R1, [R4, #8] \n" //total file size
 212       "    MOV     R0, R5 \n"       //file descriptor
 213       "    BL      sub_FF830430 \n" //function that checks something on the new file
 214       "    CMP     R0, #0 \n" 
 215       "    MOVEQ   R1, R4 \n" 
 216       "    MOVEQ   R0, #7 \n"       //check failed: close
 217       "    BEQ     loc_FFA52380 \n" 
 218 "loc_FFA5235C:\n"
 219       "    LDR     R0, [R4, #0x50] \n" 
 220       "    CMP     R0, #2 \n" 
 221       "    BEQ     loc_FFA52378 \n" 
 222       "    LDR     R0, [R4, #4] \n" 
 223       "    CMP     R0, #0 \n" 
 224       "    MOVEQ   R1, R4 \n" 
 225       "    BEQ     loc_FFA52380 \n" 
 226 "loc_FFA52378:\n"
 227       "    MOV     R1, R4 \n" 
 228       "    MOV     R0, #9 \n" // next state, the weird "append/overwrite" mode
 229 "loc_FFA52380:\n"
 230       "    BL      sub_FFA52164 \n" // send_msg_to_filewritetask
 231 "loc_FFA52384:\n"
 232       "    ADD     SP, SP, #0x3C \n" 
 233       "    LDMFD   SP!, {R4-R9,PC} \n"
 234       );
 235 }
 236 
 237 
 238 void __attribute__((naked,noinline)) sub_FFA52860_my(  ) { //write
 239 asm volatile (
 240       "    STMFD   SP!, {R4-R10,LR} \n" 
 241       "    MOV     R5, R0 \n" 
 242       "    LDR     R0, [R0] \n" 
 243       "    CMP     R0, #6 \n" 
 244       "    BHI     loc_FFA5288C \n" 
 245       "    ADD     R0, R5, R0, LSL #3 \n" 
 246       "    LDR     R8, [R0, #0x18]! \n" // first data chunk address
 247       "    LDR     R7, [R0, #4] \n" 
 248       "    CMP     R7, #0 \n" 
 249       "    BNE     loc_FFA528A4 \n" 
 250       "    B       loc_FFA52898 \n" 
 251 "loc_FFA5288C:\n"
 252       "    LDR     R1, =0x2DD \n" 
 253       "    LDR     R0, =0xFFA52668 \n" 
 254       "    BL      sub_003F6AFC \n" //DebugAssert
 255 "loc_FFA52898:\n"
 256       "    MOV     R1, R5 \n" 
 257       "    MOV     R0, #7 \n" 
 258       "    B       loc_FFA52938 \n" 
 259 "loc_FFA528A4:\n"
 260       "    LDR     R9, =0x96B8 \n" 
 261       "    MOV     R4, R7 \n" 
 262 "loc_FFA528AC:\n"
 263       "    LDR     R0, [R5, #4] \n" 
 264       "    CMP     R4, #0x1000000 \n" 
 265       "    MOVLS   R6, R4 \n" 
 266       "    MOVHI   R6, #0x1000000 \n" 
 267       "    BIC     R1, R0, #0xFF000000 \n" 
 268       "    CMP     R1, #0 \n" 
 269       "    BICNE   R0, R0, #0xFF000000 \n" 
 270       "    RSBNE   R0, R0, #0x1000000 \n" 
 271       "    CMPNE   R6, R0 \n" 
 272       "    MOVHI   R6, R0 \n" 
 273       "    LDR     R0, [R9, #8] \n" 
 274       "    MOV     R2, R6 \n" 
 275       "    MOV     R1, R8 \n" 
 276       "    BL      fwt_write\n"     // mod! sub_FF830290 Write
 277       "    LDR     R1, [R5, #4] \n"
 278       "    CMP     R6, R0 \n" 
 279       "    ADD     R1, R1, R0 \n" 
 280       "    STR     R1, [R5, #4] \n" 
 281       "    BEQ     loc_FFA5290C \n" 
 282       "    CMN     R0, #1 \n" 
 283       "    LDRNE   R0, =0x9200015 \n" 
 284       "    LDREQ   R0, =0x9200005 \n" 
 285       "    STR     R0, [R5, #0x14] \n" 
 286       "    B       loc_FFA52898 \n" 
 287 "loc_FFA5290C:\n"
 288       "    SUB     R4, R4, R0 \n" 
 289       "    CMP     R4, R7 \n" 
 290       "    ADD     R8, R8, R0 \n" 
 291       "    MOVCS   R1, #0x308 \n" 
 292       "    LDRCS   R0, =0xFFA52668 \n" 
 293       "    BLCS    sub_003F6AFC \n" //DebugAssert
 294       "    CMP     R4, #0 \n" 
 295       "    BNE     loc_FFA528AC \n" 
 296       "    LDR     R0, [R5] \n" 
 297       "    MOV     R1, R5 \n" 
 298       "    ADD     R0, R0, #1 \n" 
 299 "loc_FFA52938:\n"
 300       "    LDMFD   SP!, {R4-R10,LR} \n" 
 301       "    B       sub_FFA52164 \n" // send_msg_to_filewritetask
 302       ".ltorg\n" //+
 303       );
 304 }
 305 
 306 
 307 void __attribute__((naked,noinline)) sub_FFA5238C_my(  ) { //close
 308 asm volatile (
 309       "    STMFD   SP!, {R4-R6,LR} \n" 
 310       "    MOV     R4, R0 \n" 
 311       "    LDR     R0, [R0, #0x50] \n" 
 312       "    LDR     R5, =0x96B8 \n" 
 313       "    CMP     R0, #3 \n" 
 314       "    SUB     SP, SP, #0x38 \n" 
 315       "    BEQ     loc_FFA52504 \n" 
 316       "    LDR     R0, [R5, #8] \n" 
 317       "    CMN     R0, #1 \n" 
 318       "    BEQ     loc_FFA523E0 \n" 
 319       "    LDR     R1, [R4, #0xC] \n" 
 320       "    LDR     R6, =0x9200003 \n" 
 321       "    TST     R1, #0x8000 \n" 
 322       "    BEQ     loc_FFA523CC \n" 
 323 //mod start      
 324       "LDR R3, =current_write_ignored\n"
 325       "LDR R3, [R3]\n"
 326       "CMP R3, #0\n"
 327       "BNE loc_FFA523CC\n" // jump over the next block
 328 //mod end
 329       "    BL      sub_FF83015C \n"     // fsionotify related
 330       "    B       loc_FFA523D0 \n" 
 331 "loc_FFA523CC:\n"
 332       "    BL      fwt_close\n"         // mod! sub_FF830158 Close
 333 "loc_FFA523D0:\n"
 334       "    CMP     R0, #0 \n" 
 335       "    MVN     R0, #0 \n" 
 336       "    STRNE   R6, [R4, #0x14] \n" 
 337       "    STR     R0, [R5, #8] \n" 
 338 "loc_FFA523E0:\n"
 339       "    LDR     R0, [R4, #0x14] \n" 
 340       "    TST     R0, #1 \n" 
 341       "    BNE     loc_FFA524E8 \n" 
 342       "    LDR     R0, [R4, #0xC] \n" 
 343       "    TST     R0, #8 \n" 
 344       "    BNE     loc_FFA52404 \n" 
 345       "    LDR     R0, [R4, #0x50] \n" 
 346       "    CMP     R0, #3 \n" 
 347       "    BNE     loc_FFA52434 \n" 
 348 "loc_FFA52404:\n"
 349       "    ADD     R1, SP, #0x20 \n" 
 350       "    ADD     R0, R4, #0x54 \n" 
 351       "    BL      sub_FF863F40 \n" 
 352       "    CMP     R0, #0 \n" 
 353       "    LDREQ   R1, =0x346 \n" 
 354       "    LDREQ   R0, =0xFFA52668 \n" 
 355       "    BLEQ    sub_003F6AFC \n" //DebugAssert
 356       "    LDR     R0, [SP, #0x28] \n" 
 357       "    LDR     R1, [R4, #4] \n" 
 358       "    ADD     R0, R0, R1 \n" 
 359       "    STR     R0, [SP, #0x28] \n" 
 360       "    B       loc_FFA52464 \n" 
 361 "loc_FFA52434:\n"
 362       "    LDR     R0, =0x81FF \n" 
 363       "    STR     R0, [SP, #0x20] \n" 
 364       "    MOV     R0, #0x20 \n" 
 365       "    STR     R0, [SP, #0x24] \n" 
 366       "    LDR     R0, [R4, #4] \n" 
 367       "    STR     R0, [SP, #0x28] \n" 
 368       "    LDR     R0, [R4, #0x10] \n" 
 369       "    STR     R0, [SP, #0x2C] \n" 
 370       "    LDR     R0, [R4, #0x10] \n" 
 371       "    STR     R0, [SP, #0x30] \n" 
 372       "    LDR     R0, [R4, #0x10] \n" 
 373       "    STR     R0, [SP, #0x34] \n" 
 374 "loc_FFA52464:\n"
 375       "    LDR     R0, [R4, #0x50] \n" 
 376       "    CMP     R0, #2 \n" 
 377       "    BEQ     loc_FFA524E8 \n" 
 378       "    ADD     R1, SP, #0x20 \n" 
 379       "    ADD     R0, R4, #0x54 \n" 
 380       "    BL      sub_FF863FF8 \n" 
 381       "    LDR     R0, [R4, #0x50] \n" 
 382       "    CMP     R0, #1 \n" 
 383       "    BNE     loc_FFA524E8 \n" 
 384       "    MOV     R2, #0x20 \n" 
 385       "    ADD     R1, R4, #0x54 \n" 
 386       "    MOV     R0, SP \n" 
 387       "    BL      sub_003FC364 \n" 
 388       "    MOV     R0, SP \n" 
 389       "    BL      sub_FF812E38 \n" 
 390       "    MOV     R2, #0x54 \n" 
 391       "    ADD     R0, R0, SP \n" 
 392       "    MOV     R1, #0x4D \n" 
 393       "    STRB    R2, [R0, #-3] \n" 
 394       "    STRB    R1, [R0, #-2] \n" 
 395       "    MOV     R1, #0x50 \n" 
 396       "    STRB    R1, [R0, #-1] \n" 
 397       "    MOV     R1, SP \n" 
 398       "    ADD     R0, R4, #0x54 \n" 
 399       "    BL      sub_FF863878 \n" 
 400       "    CMP     R0, #0 \n" 
 401       "    MOVEQ   R1, #0x164 \n" 
 402       "    LDREQ   R0, =0xFFA52668 \n" 
 403       "    BLEQ    sub_003F6AFC \n" //DebugAssert
 404       "    MOV     R0, SP \n" 
 405       "    BL      sub_FF864454 \n" 
 406       "    ADD     R0, R4, #0x54 \n" 
 407       "    BL      sub_FF864454 \n" 
 408 "loc_FFA524E8:\n"
 409       "    ADD     R0, R4, #0x54 \n" 
 410       "    BL      sub_FF86671C \n" // path check or something
 411       "    LDR     R1, [R5, #0x1C] \n" 
 412       "    BL      sub_FF8647B8 \n" 
 413       "    MOV     R0, #0 \n" 
 414       "    STR     R0, [R5, #4] \n" 
 415       "    B       loc_FFA5250C \n" 
 416 "loc_FFA52504:\n"
 417       "    LDR     R0, [R5, #0x1C] \n" 
 418       "    BLX     R0 \n" 
 419 "loc_FFA5250C:\n"
 420       "    LDR     R1, [R5, #0x18] \n" 
 421       "    CMP     R1, #0 \n" 
 422       "    LDRNE   R0, [R4, #0x14] \n" 
 423       "    BLXNE   R1 \n" 
 424       "    ADD     SP, SP, #0x38 \n" 
 425       "    LDMFD   SP!, {R4-R6,PC} \n"
 426       );
 427 }

/* [<][>][^][v][top][bottom][index][help] */