root/platform/ixus240_elph320hs/sub/102a/filewrite.c

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FF3A0CDC_my
  3. sub_FF3A131C_my
  4. sub_FF3A0E48_my

   1 /*
   2  * filewrite.c - auto-generated by CHDK code_gen.
   3  */
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 
   7 typedef struct {
   8     unsigned int address;
   9     unsigned int length;
  10 } cam_ptp_data_chunk; //camera specific structure
  11 
  12 #define MAX_CHUNKS_FOR_JPEG 7   // filewritetask is prepared for this many chunks
  13 /*
  14  * fwt_data_struct: defined here as it's camera dependent
  15  * unneeded members are designated with unkn
  16  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  17  * pdc is always required
  18  * name is not currently used
  19  */
  20 typedef struct
  21 {
  22     int unkn1;
  23     int file_offset;
  24     int full_size;
  25     int unkn2, unkn3, unkn4;
  26     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_JPEG];
  27     int seek_flag;
  28     char name[32];       // open stage: sub_FF3A0CA8 (1.01a) --> "ADD     R0, R4, #0x54"
  29                          // offset of 'name' from start = 0x54 = 84 bytes = 21 words
  30 } fwt_data_struct;
  31 #define FWT_MUSTSEEK    2   // value of the masked seek_flag indicating seek is required
  32 #define FWT_SEEKMASK    0xffffffff   // masks out unneeded bits of seek_flag
  33 
  34 #include "../../../generic/filewrite.c"
  35 
  36 /*************************************************************/
  37 //** filewritetask @ 0xFF3A0FE0 - 0xFF3A1124, length=82
  38 void __attribute__((naked,noinline)) filewritetask() {
  39 asm volatile (
  40 "    STMFD   SP!, {R1-R7,LR} \n"
  41 "    LDR     R7, =0x101E4 \n"
  42 "    MOV     R6, #0 \n"
  43 
  44 "loc_FF3A0FEC:\n"
  45 "    LDR     R0, [R7, #0x14] \n"
  46 "    MOV     R2, #0 \n"
  47 "    ADD     R1, SP, #8 \n"
  48 "    MOV     R5, R7 \n"
  49 "    BL      sub_0068EF6C /*_ReceiveMessageQueue*/ \n"
  50 "    CMP     R0, #0 \n"
  51 "    LDRNE   R1, =0x38E \n"
  52 "    LDRNE   R0, =0xFF3A1124 /*'dwFWrite.c'*/ \n"
  53 "    BLNE    _DebugAssert \n"
  54 "    LDR     R0, [SP, #8] \n"
  55 "    LDR     R1, [R0] \n"
  56 "    CMP     R1, #0xB \n"
  57 "    ADDCC   PC, PC, R1, LSL#2 \n"
  58 "    B       loc_FF3A0FEC \n"
  59 "    B       loc_FF3A10F4 \n"
  60 "    B       loc_FF3A10F4 \n"
  61 "    B       loc_FF3A10F4 \n"
  62 "    B       loc_FF3A10F4 \n"
  63 "    B       loc_FF3A10F4 \n"
  64 "    B       loc_FF3A10F4 \n"
  65 "    B       loc_FF3A10F4 \n"
  66 "    B       loc_FF3A10FC \n"
  67 "    B       loc_FF3A1050 \n"
  68 "    B       loc_FF3A10C0 \n"
  69 "    B       loc_FF3A10B8 \n"
  70 
  71 "loc_FF3A1050:\n"
  72 "    STR     R6, [SP] \n"
  73 
  74 "loc_FF3A1054:\n"
  75 "    LDR     R0, [R5, #0x14] \n"
  76 "    MOV     R1, SP \n"
  77 "    BL      sub_0068F1B0 /*_GetNumberOfPostedMessages*/ \n"
  78 "    LDR     R0, [SP] \n"
  79 "    CMP     R0, #0 \n"
  80 "    BEQ     loc_FF3A1080 \n"
  81 "    LDR     R0, [R5, #0x14] \n"
  82 "    MOV     R2, #0 \n"
  83 "    ADD     R1, SP, #4 \n"
  84 "    BL      sub_0068EF6C /*_ReceiveMessageQueue*/ \n"
  85 "    B       loc_FF3A1054 \n"
  86 
  87 "loc_FF3A1080:\n"
  88 "    LDR     R0, [R5, #8] \n"
  89 "    CMN     R0, #1 \n"
  90 "    BEQ     loc_FF3A10AC \n"
  91 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
  92 "    MVN     R0, #0 \n"
  93 "    STR     R0, [R5, #8] \n"
  94 "    LDR     R0, =0x2255BC \n"
  95 "    STR     R6, [R5, #4] \n"
  96 "    BL      sub_FF078994 \n"
  97 "    MOV     R1, #0 \n"
  98 "    BL      sub_FF076C78 \n"
  99 
 100 "loc_FF3A10AC:\n"
 101 "    LDR     R0, [R5, #0x10] \n"
 102 "    BL      _GiveSemaphore \n"
 103 "    B       loc_FF3A0FEC \n"
 104 
 105 "loc_FF3A10B8:\n"
 106 "    BL      sub_FF3A0CDC_my \n"  // --> Patched. Old value = 0xFF3A0CDC. Open stage
 107 "    B       loc_FF3A0FEC \n"
 108 
 109 "loc_FF3A10C0:\n"
 110 "    LDR     R1, [R0, #4] \n"
 111 "    MOV     R4, R0 \n"
 112 "    LDR     R0, [R5, #8] \n"
 113 "    MOV     R2, #0 \n"
 114 "    BL      fwt_lseek \n"  // --> Patched. Old value = _lseek.
 115 "    CMN     R0, #1 \n"
 116 "    LDREQ   R0, =0x9200013 \n"
 117 "    MOV     R1, R4 \n"
 118 "    STREQ   R0, [R4, #0x14] \n"
 119 "    MOVNE   R0, #0 \n"
 120 "    MOVEQ   R0, #7 \n"
 121 "    BL      sub_FF3A0C20 \n"
 122 "    B       loc_FF3A0FEC \n"
 123 
 124 "loc_FF3A10F4:\n"
 125 "    BL      sub_FF3A131C_my \n"  // --> Patched. Old value = 0xFF3A131C. Write stage
 126 "    B       loc_FF3A0FEC \n"
 127 
 128 "loc_FF3A10FC:\n"
 129 "    BL      sub_FF3A0E48_my \n"  // --> Patched. Old value = 0xFF3A0E48. Close stage
 130 "    B       loc_FF3A0FEC \n"
 131 );
 132 }
 133 
 134 /*************************************************************/
 135 //** sub_FF3A0CDC_my @ 0xFF3A0CDC - 0xFF3A0E44, length=91
 136 void __attribute__((naked,noinline)) sub_FF3A0CDC_my() {
 137 asm volatile (
 138 "    STMFD   SP!, {R4-R9,LR} \n"
 139 "    LDR     R6, =0x101E4 \n"
 140 "    MOV     R4, R0 \n"
 141 //hook start placed here to avoid bne a few instructions below
 142 //R0 holds data block start
 143 "    STMFD   SP!, {R4-R12,LR}\n"
 144 "    BL      filewrite_main_hook\n"
 145 "    LDMFD   SP!, {R4-R12,LR}\n"
 146 //hook end
 147 "    LDR     R0, [R6, #4] \n"
 148 "    SUB     SP, SP, #0x3C \n"
 149 "    CMP     R0, #0 \n"
 150 "    BNE     loc_FF3A0E18 \n"
 151 "    ADD     R0, R4, #0x54 \n"
 152 "    BL      sub_FF078994 \n"
 153 "    MOV     R1, #0 \n"
 154 "    BL      sub_FF076B3C \n"
 155 "    LDR     R0, [R4, #0x10] \n"
 156 "    BL      sub_FF000370 \n"
 157 "    LDR     R0, [R4, #0x50] \n"
 158 "    LDR     R9, =0x1B6 \n"
 159 "    CMP     R0, #1 \n"
 160 "    LDREQ   R0, [R4, #0xC] \n"
 161 "    ADD     R7, R4, #0x54 \n"
 162 "    ORREQ   R0, R0, #0x8000 \n"
 163 "    STREQ   R0, [R4, #0xC] \n"
 164 "    LDR     R8, [R4, #0xC] \n"
 165 "    LDR     R5, [R4, #0x10] \n"
 166 "    MOV     R2, R9 \n"
 167 "    MOV     R1, R8 \n"
 168 "    MOV     R0, R7 \n"
 169 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 170 "    CMN     R0, #1 \n"
 171 "    BNE     loc_FF3A0DA8 \n"
 172 "    MOV     R0, R7 \n"
 173 "    BL      sub_FF0288BC \n"
 174 "    MOV     R2, #0xF \n"
 175 "    MOV     R1, R7 \n"
 176 "    ADD     R0, SP, #4 \n"
 177 "    BL      sub_006AB5FC \n"
 178 "    MOV     R0, #0 \n"
 179 "    LDR     R1, =0x41FF \n"
 180 "    STRB    R0, [SP, #0x13] \n"
 181 "    STR     R1, [SP, #0x24] \n"
 182 "    MOV     R1, #0x10 \n"
 183 "    STR     R0, [SP, #0x2C] \n"
 184 "    STR     R1, [SP, #0x28] \n"
 185 "    ADD     R1, SP, #0x24 \n"
 186 "    ADD     R0, SP, #4 \n"
 187 "    STR     R5, [SP, #0x30] \n"
 188 "    STR     R5, [SP, #0x34] \n"
 189 "    STR     R5, [SP, #0x38] \n"
 190 "    BL      sub_FF0764B8 \n"
 191 "    MOV     R2, R9 \n"
 192 "    MOV     R1, R8 \n"
 193 "    MOV     R0, R7 \n"
 194 "    BL      _Open \n"
 195 
 196 "loc_FF3A0DA8:\n"
 197 "    CMN     R0, #1 \n"
 198 "    MOV     R5, R0 \n"
 199 "    STR     R0, [R6, #8] \n"
 200 "    BNE     loc_FF3A0DE4 \n"
 201 "    ADD     R0, R4, #0x54 \n"
 202 "    BL      sub_FF078994 \n"
 203 "    LDR     R1, [R6, #0x1C] \n"
 204 "    BL      sub_FF076C78 \n"
 205 "    LDR     R1, [R6, #0x18] \n"
 206 "    CMP     R1, #0 \n"
 207 "    BEQ     loc_FF3A0E40 \n"
 208 "    ADD     SP, SP, #0x3C \n"
 209 "    LDMFD   SP!, {R4-R9,LR} \n"
 210 "    LDR     R0, =0x9200001 \n"
 211 "    BX      R1 \n"
 212 
 213 "loc_FF3A0DE4:\n"
 214 "    MOV     R0, #1 \n"
 215 "    STR     R0, [R6, #4] \n"
 216 "    LDR     R0, =0x2255BC \n"
 217 "    MOV     R2, #0x20 \n"
 218 "    ADD     R1, R4, #0x54 \n"
 219 "    BL      sub_006AB7E4 \n"
 220 //mod start
 221 "    LDR     R3, =current_write_ignored\n"
 222 "    LDR     R3, [R3]\n"
 223 "    CMP     R3, #0\n"
 224 "    BNE     loc_A\n" // jump over the next block
 225 //mod end
 226 "    LDR     R1, [R4, #8] \n"
 227 "    MOV     R0, R5 \n"
 228 "    BL      sub_FF02858C \n"
 229 "    CMP     R0, #0 \n"
 230 "    MOVEQ   R1, R4 \n"
 231 "    MOVEQ   R0, #7 \n"
 232 "    BEQ     loc_FF3A0E3C \n"
 233 
 234 "loc_FF3A0E18:\n"
 235 "loc_A:\n"
 236 "    LDR     R0, [R4, #0x50] \n"
 237 "    CMP     R0, #2 \n"
 238 "    BEQ     loc_FF3A0E34 \n"
 239 "    LDR     R0, [R4, #4] \n"
 240 "    CMP     R0, #0 \n"
 241 "    MOVEQ   R1, R4 \n"
 242 "    BEQ     loc_FF3A0E3C \n"
 243 
 244 "loc_FF3A0E34:\n"
 245 "    MOV     R1, R4 \n"
 246 "    MOV     R0, #9 \n"
 247 
 248 "loc_FF3A0E3C:\n"
 249 "    BL      sub_FF3A0C20 \n"
 250 
 251 "loc_FF3A0E40:\n"
 252 "    ADD     SP, SP, #0x3C \n"
 253 "    LDMFD   SP!, {R4-R9,PC} \n"
 254 );
 255 }
 256 
 257 /*************************************************************/
 258 //** sub_FF3A131C_my @ 0xFF3A131C - 0xFF3A13F8, length=56
 259 void __attribute__((naked,noinline)) sub_FF3A131C_my() {
 260 asm volatile (
 261 "    STMFD   SP!, {R4-R10,LR} \n"
 262 "    MOV     R5, R0 \n"
 263 "    LDR     R0, [R0] \n"
 264 "    CMP     R0, #6 \n"
 265 "    BHI     loc_FF3A1348 \n"
 266 "    ADD     R0, R5, R0, LSL#3 \n"
 267 "    LDR     R8, [R0, #0x18]! \n"
 268 "    LDR     R7, [R0, #4] \n"
 269 "    CMP     R7, #0 \n"
 270 "    BNE     loc_FF3A1360 \n"
 271 "    B       loc_FF3A1354 \n"
 272 
 273 "loc_FF3A1348:\n"
 274 "    LDR     R1, =0x2DD \n"
 275 "    LDR     R0, =0xFF3A1124 /*'dwFWrite.c'*/ \n"
 276 "    BL      _DebugAssert \n"
 277 
 278 "loc_FF3A1354:\n"
 279 "    MOV     R1, R5 \n"
 280 "    MOV     R0, #7 \n"
 281 "    B       loc_FF3A13F4 \n"
 282 
 283 "loc_FF3A1360:\n"
 284 "    LDR     R9, =0x101E4 \n"
 285 "    MOV     R4, R7 \n"
 286 
 287 "loc_FF3A1368:\n"
 288 "    LDR     R0, [R5, #4] \n"
 289 "    CMP     R4, #0x1000000 \n"
 290 "    MOVLS   R6, R4 \n"
 291 "    MOVHI   R6, #0x1000000 \n"
 292 "    BIC     R1, R0, #0xFF000000 \n"
 293 "    CMP     R1, #0 \n"
 294 "    BICNE   R0, R0, #0xFF000000 \n"
 295 "    RSBNE   R0, R0, #0x1000000 \n"
 296 "    CMPNE   R6, R0 \n"
 297 "    MOVHI   R6, R0 \n"
 298 "    LDR     R0, [R9, #8] \n"
 299 "    MOV     R2, R6 \n"
 300 "    MOV     R1, R8 \n"
 301 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 302 "    LDR     R1, [R5, #4] \n"
 303 "    CMP     R6, R0 \n"
 304 "    ADD     R1, R1, R0 \n"
 305 "    STR     R1, [R5, #4] \n"
 306 "    BEQ     loc_FF3A13C8 \n"
 307 "    CMN     R0, #1 \n"
 308 "    LDRNE   R0, =0x9200015 \n"
 309 "    LDREQ   R0, =0x9200005 \n"
 310 "    STR     R0, [R5, #0x14] \n"
 311 "    B       loc_FF3A1354 \n"
 312 
 313 "loc_FF3A13C8:\n"
 314 "    SUB     R4, R4, R0 \n"
 315 "    CMP     R4, R7 \n"
 316 "    ADD     R8, R8, R0 \n"
 317 "    MOVCS   R1, #0x308 \n"
 318 "    LDRCS   R0, =0xFF3A1124 /*'dwFWrite.c'*/ \n"
 319 "    BLCS    _DebugAssert \n"
 320 "    CMP     R4, #0 \n"
 321 "    BNE     loc_FF3A1368 \n"
 322 "    LDR     R0, [R5] \n"
 323 "    MOV     R1, R5 \n"
 324 "    ADD     R0, R0, #1 \n"
 325 
 326 "loc_FF3A13F4:\n"
 327 "    LDMFD   SP!, {R4-R10,LR} \n"
 328 "    B       sub_FF3A0C20 \n"
 329 );
 330 }
 331 
 332 /*************************************************************/
 333 //** sub_FF3A0E48_my @ 0xFF3A0E48 - 0xFF3A0FDC, length=102
 334 void __attribute__((naked,noinline)) sub_FF3A0E48_my() {
 335 asm volatile (
 336 "    STMFD   SP!, {R4-R6,LR} \n"
 337 "    MOV     R4, R0 \n"
 338 "    LDR     R0, [R0, #0x50] \n"
 339 "    LDR     R5, =0x101E4 \n"
 340 "    CMP     R0, #3 \n"
 341 "    SUB     SP, SP, #0x38 \n"
 342 "    BEQ     loc_FF3A0FC0 \n"
 343 "    LDR     R0, [R5, #8] \n"
 344 "    CMN     R0, #1 \n"
 345 "    BEQ     loc_FF3A0E9C \n"
 346 "    LDR     R1, [R4, #0xC] \n"
 347 "    LDR     R6, =0x9200003 \n"
 348 "    TST     R1, #0x8000 \n"
 349 "    BEQ     loc_FF3A0E88 \n"
 350 //mod start
 351 "    LDR     R3, =current_write_ignored\n"
 352 "    LDR     R3, [R3]\n"
 353 "    CMP     R3, #0\n"
 354 "    BNE     loc_B\n" // jump over the next block
 355 //mod end
 356 "    BL      sub_FF0282E0 \n"
 357 "    B       loc_FF3A0E8C \n"
 358 
 359 "loc_FF3A0E88:\n"
 360 "loc_B:\n"
 361 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 362 
 363 "loc_FF3A0E8C:\n"
 364 "    CMP     R0, #0 \n"
 365 "    MVN     R0, #0 \n"
 366 "    STRNE   R6, [R4, #0x14] \n"
 367 "    STR     R0, [R5, #8] \n"
 368 
 369 "loc_FF3A0E9C:\n"
 370 "    LDR     R0, [R4, #0x14] \n"
 371 "    TST     R0, #1 \n"
 372 "    BNE     loc_FF3A0FA4 \n"
 373 "    LDR     R0, [R4, #0xC] \n"
 374 "    TST     R0, #8 \n"
 375 "    BNE     loc_FF3A0EC0 \n"
 376 "    LDR     R0, [R4, #0x50] \n"
 377 "    CMP     R0, #3 \n"
 378 "    BNE     loc_FF3A0EF0 \n"
 379 
 380 "loc_FF3A0EC0:\n"
 381 "    ADD     R1, SP, #0x20 \n"
 382 "    ADD     R0, R4, #0x54 \n"
 383 "    BL      sub_FF076400 \n"
 384 "    CMP     R0, #0 \n"
 385 "    LDREQ   R1, =0x346 \n"
 386 "    LDREQ   R0, =0xFF3A1124 /*'dwFWrite.c'*/ \n"
 387 "    BLEQ    _DebugAssert \n"
 388 "    LDR     R0, [SP, #0x28] \n"
 389 "    LDR     R1, [R4, #4] \n"
 390 "    ADD     R0, R0, R1 \n"
 391 "    STR     R0, [SP, #0x28] \n"
 392 "    B       loc_FF3A0F20 \n"
 393 
 394 "loc_FF3A0EF0:\n"
 395 "    LDR     R0, =0x81FF \n"
 396 "    STR     R0, [SP, #0x20] \n"
 397 "    MOV     R0, #0x20 \n"
 398 "    STR     R0, [SP, #0x24] \n"
 399 "    LDR     R0, [R4, #4] \n"
 400 "    STR     R0, [SP, #0x28] \n"
 401 "    LDR     R0, [R4, #0x10] \n"
 402 "    STR     R0, [SP, #0x2C] \n"
 403 "    LDR     R0, [R4, #0x10] \n"
 404 "    STR     R0, [SP, #0x30] \n"
 405 "    LDR     R0, [R4, #0x10] \n"
 406 "    STR     R0, [SP, #0x34] \n"
 407 
 408 "loc_FF3A0F20:\n"
 409 "    LDR     R0, [R4, #0x50] \n"
 410 "    CMP     R0, #2 \n"
 411 "    BEQ     loc_FF3A0FA4 \n"
 412 "    ADD     R1, SP, #0x20 \n"
 413 "    ADD     R0, R4, #0x54 \n"
 414 "    BL      sub_FF0764B8 \n"
 415 "    LDR     R0, [R4, #0x50] \n"
 416 "    CMP     R0, #1 \n"
 417 "    BNE     loc_FF3A0FA4 \n"
 418 "    MOV     R2, #0x20 \n"
 419 "    ADD     R1, R4, #0x54 \n"
 420 "    MOV     R0, SP \n"
 421 "    BL      sub_006AB7E4 \n"
 422 "    MOV     R0, SP \n"
 423 "    BL      _strlen \n"
 424 "    MOV     R2, #0x54 \n"
 425 "    ADD     R0, R0, SP \n"
 426 "    MOV     R1, #0x4D \n"
 427 "    STRB    R2, [R0, #-3] \n"
 428 "    STRB    R1, [R0, #-2] \n"
 429 "    MOV     R1, #0x50 \n"
 430 "    STRB    R1, [R0, #-1] \n"
 431 "    MOV     R1, SP \n"
 432 "    ADD     R0, R4, #0x54 \n"
 433 "    BL      sub_FF075D50 \n"
 434 "    CMP     R0, #0 \n"
 435 "    MOVEQ   R1, #0x164 \n"
 436 "    LDREQ   R0, =0xFF3A1124 /*'dwFWrite.c'*/ \n"
 437 "    BLEQ    _DebugAssert \n"
 438 "    MOV     R0, SP \n"
 439 "    BL      sub_FF076914 \n"
 440 "    ADD     R0, R4, #0x54 \n"
 441 "    BL      sub_FF076914 \n"
 442 
 443 "loc_FF3A0FA4:\n"
 444 "    ADD     R0, R4, #0x54 \n"
 445 "    BL      sub_FF078994 \n"
 446 "    LDR     R1, [R5, #0x1C] \n"
 447 "    BL      sub_FF076C78 \n"
 448 "    MOV     R0, #0 \n"
 449 "    STR     R0, [R5, #4] \n"
 450 "    B       loc_FF3A0FC8 \n"
 451 
 452 "loc_FF3A0FC0:\n"
 453 "    LDR     R0, [R5, #0x1C] \n"
 454 "    BLX     R0 \n"
 455 
 456 "loc_FF3A0FC8:\n"
 457 "    LDR     R1, [R5, #0x18] \n"
 458 "    CMP     R1, #0 \n"
 459 "    LDRNE   R0, [R4, #0x14] \n"
 460 "    BLXNE   R1 \n"
 461 "    ADD     SP, SP, #0x38 \n"
 462 "    LDMFD   SP!, {R4-R6,PC} \n"
 463 );
 464 }

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