root/platform/ixus125_elph110hs/sub/100e/filewrite.c

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FF2FB0F8_my
  3. sub_FF2FB738_my
  4. sub_FF2FB264_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_FWT 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_FWT];
  27     int seek_flag;
  28     char name[32];
  29 } fwt_data_struct;
  30 #define FWT_MUSTSEEK    2   // value of the masked seek_flag indicating seek is required
  31 #define FWT_SEEKMASK    0xffffffff   // masks out unneeded bits of seek_flag
  32 
  33 #include "../../../generic/filewrite.c"
  34 
  35 /*************************************************************/
  36 //** filewritetask @ 0xFF2FB3FC - 0xFF2FB540, length=82
  37 void __attribute__((naked,noinline)) filewritetask() {
  38 asm volatile (
  39 "    STMFD   SP!, {R1-R7,LR} \n"
  40 "    LDR     R7, =0xE704 \n"
  41 "    MOV     R6, #0 \n"
  42 
  43 "loc_FF2FB408:\n"
  44 "    LDR     R0, [R7, #0x14] \n"
  45 "    MOV     R2, #0 \n"
  46 "    ADD     R1, SP, #8 \n"
  47 "    MOV     R5, R7 \n"
  48 "    BL      sub_0068BBE4 /*_ReceiveMessageQueue*/ \n"
  49 "    CMP     R0, #0 \n"
  50 "    LDRNE   R1, =0x38E \n"
  51 "    LDRNE   R0, =0xFF2FB540 /*'dwFWrite.c'*/ \n"
  52 "    BLNE    _DebugAssert \n"
  53 "    LDR     R0, [SP, #8] \n"
  54 "    LDR     R1, [R0] \n"
  55 "    CMP     R1, #0xB \n"
  56 "    ADDCC   PC, PC, R1, LSL#2 \n"
  57 "    B       loc_FF2FB408 \n"
  58 "    B       loc_FF2FB510 \n"
  59 "    B       loc_FF2FB510 \n"
  60 "    B       loc_FF2FB510 \n"
  61 "    B       loc_FF2FB510 \n"
  62 "    B       loc_FF2FB510 \n"
  63 "    B       loc_FF2FB510 \n"
  64 "    B       loc_FF2FB510 \n"
  65 "    B       loc_FF2FB518 \n"
  66 "    B       loc_FF2FB46C \n"
  67 "    B       loc_FF2FB4DC \n"
  68 "    B       loc_FF2FB4D4 \n"
  69 
  70 "loc_FF2FB46C:\n"
  71 "    STR     R6, [SP] \n"
  72 
  73 "loc_FF2FB470:\n"
  74 "    LDR     R0, [R5, #0x14] \n"
  75 "    MOV     R1, SP \n"
  76 "    BL      sub_0068BE28 /*_GetNumberOfPostedMessages*/ \n"
  77 "    LDR     R0, [SP] \n"
  78 "    CMP     R0, #0 \n"
  79 "    BEQ     loc_FF2FB49C \n"
  80 "    LDR     R0, [R5, #0x14] \n"
  81 "    MOV     R2, #0 \n"
  82 "    ADD     R1, SP, #4 \n"
  83 "    BL      sub_0068BBE4 /*_ReceiveMessageQueue*/ \n"
  84 "    B       loc_FF2FB470 \n"
  85 
  86 "loc_FF2FB49C:\n"
  87 "    LDR     R0, [R5, #8] \n"
  88 "    CMN     R0, #1 \n"
  89 "    BEQ     loc_FF2FB4C8 \n"
  90 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
  91 "    MVN     R0, #0 \n"
  92 "    STR     R0, [R5, #8] \n"
  93 "    LDR     R0, =0x15739C \n"
  94 "    STR     R6, [R5, #4] \n"
  95 "    BL      sub_FF05C27C \n"
  96 "    MOV     R1, #0 \n"
  97 "    BL      sub_FF05A2E4 \n"
  98 
  99 "loc_FF2FB4C8:\n"
 100 "    LDR     R0, [R5, #0x10] \n"
 101 "    BL      _GiveSemaphore \n"
 102 "    B       loc_FF2FB408 \n"
 103 
 104 "loc_FF2FB4D4:\n"
 105 "    BL      sub_FF2FB0F8_my \n"  // --> Patched. Old value = 0xFF2FB0F8. Open stage
 106 "    B       loc_FF2FB408 \n"
 107 
 108 "loc_FF2FB4DC:\n"
 109 "    LDR     R1, [R0, #4] \n"
 110 "    MOV     R4, R0 \n"
 111 "    LDR     R0, [R5, #8] \n"
 112 "    MOV     R2, #0 \n"
 113 "    BL      fwt_lseek \n"  // --> Patched. Old value = _lseek.
 114 "    CMN     R0, #1 \n"
 115 "    LDREQ   R0, =0x9200013 \n"
 116 "    MOV     R1, R4 \n"
 117 "    STREQ   R0, [R4, #0x14] \n"
 118 "    MOVNE   R0, #0 \n"
 119 "    MOVEQ   R0, #7 \n"
 120 "    BL      sub_FF2FB03C \n"
 121 "    B       loc_FF2FB408 \n"
 122 
 123 "loc_FF2FB510:\n"
 124 "    BL      sub_FF2FB738_my \n"  // --> Patched. Old value = 0xFF2FB738. Write stage
 125 "    B       loc_FF2FB408 \n"
 126 
 127 "loc_FF2FB518:\n"
 128 "    BL      sub_FF2FB264_my \n"  // --> Patched. Old value = 0xFF2FB264. Close stage
 129 "    B       loc_FF2FB408 \n"
 130 );
 131 }
 132 
 133 /*************************************************************/
 134 //** sub_FF2FB0F8_my @ 0xFF2FB0F8 - 0xFF2FB260, length=91
 135 void __attribute__((naked,noinline)) sub_FF2FB0F8_my() {
 136 asm volatile (
 137 "    STMFD   SP!, {R4-R9,LR} \n"
 138 "    LDR     R6, =0xE704 \n"
 139 "    MOV     R4, R0 \n"
 140 //hook start placed here to avoid bne a few instructions below
 141 //R0 holds data block start
 142 "    STMFD   SP!, {R4-R12,LR}\n"
 143 "    BL      filewrite_main_hook\n"
 144 "    LDMFD   SP!, {R4-R12,LR}\n"
 145 //hook end
 146 "    LDR     R0, [R6, #4] \n"
 147 "    SUB     SP, SP, #0x3C \n"
 148 "    CMP     R0, #0 \n"
 149 "    BNE     loc_FF2FB234 \n"
 150 "    ADD     R0, R4, #0x54 \n"
 151 "    BL      sub_FF05C27C \n"
 152 "    MOV     R1, #0 \n"
 153 "    BL      sub_FF05A1A8 \n"
 154 "    LDR     R0, [R4, #0x10] \n"
 155 "    BL      sub_FF000370 \n"
 156 "    LDR     R0, [R4, #0x50] \n"
 157 "    LDR     R9, =0x1B6 \n"
 158 "    CMP     R0, #1 \n"
 159 "    LDREQ   R0, [R4, #0xC] \n"
 160 "    ADD     R7, R4, #0x54 \n"
 161 "    ORREQ   R0, R0, #0x8000 \n"
 162 "    STREQ   R0, [R4, #0xC] \n"
 163 "    LDR     R8, [R4, #0xC] \n"
 164 "    LDR     R5, [R4, #0x10] \n"
 165 "    MOV     R2, R9 \n"
 166 "    MOV     R1, R8 \n"
 167 "    MOV     R0, R7 \n"
 168 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 169 "    CMN     R0, #1 \n"
 170 "    BNE     loc_FF2FB1C4 \n"
 171 "    MOV     R0, R7 \n"
 172 "    BL      sub_FF021718 \n"
 173 "    MOV     R2, #0xF \n"
 174 "    MOV     R1, R7 \n"
 175 "    ADD     R0, SP, #4 \n"
 176 "    BL      sub_0069017C \n"
 177 "    MOV     R0, #0 \n"
 178 "    LDR     R1, =0x41FF \n"
 179 "    STRB    R0, [SP, #0x13] \n"
 180 "    STR     R1, [SP, #0x24] \n"
 181 "    MOV     R1, #0x10 \n"
 182 "    STR     R0, [SP, #0x2C] \n"
 183 "    STR     R1, [SP, #0x28] \n"
 184 "    ADD     R1, SP, #0x24 \n"
 185 "    ADD     R0, SP, #4 \n"
 186 "    STR     R5, [SP, #0x30] \n"
 187 "    STR     R5, [SP, #0x34] \n"
 188 "    STR     R5, [SP, #0x38] \n"
 189 "    BL      sub_FF059B24 \n"
 190 "    MOV     R2, R9 \n"
 191 "    MOV     R1, R8 \n"
 192 "    MOV     R0, R7 \n"
 193 "    BL      _Open \n"
 194 
 195 "loc_FF2FB1C4:\n"
 196 "    CMN     R0, #1 \n"
 197 "    MOV     R5, R0 \n"
 198 "    STR     R0, [R6, #8] \n"
 199 "    BNE     loc_FF2FB200 \n"
 200 "    ADD     R0, R4, #0x54 \n"
 201 "    BL      sub_FF05C27C \n"
 202 "    LDR     R1, [R6, #0x1C] \n"
 203 "    BL      sub_FF05A2E4 \n"
 204 "    LDR     R1, [R6, #0x18] \n"
 205 "    CMP     R1, #0 \n"
 206 "    BEQ     loc_FF2FB25C \n"
 207 "    ADD     SP, SP, #0x3C \n"
 208 "    LDMFD   SP!, {R4-R9,LR} \n"
 209 "    LDR     R0, =0x9200001 \n"
 210 "    BX      R1 \n"
 211 
 212 "loc_FF2FB200:\n"
 213 "    MOV     R0, #1 \n"
 214 "    STR     R0, [R6, #4] \n"
 215 "    LDR     R0, =0x15739C \n"
 216 "    MOV     R2, #0x20 \n"
 217 "    ADD     R1, R4, #0x54 \n"
 218 "    BL      sub_00690364 \n"
 219 //mod start
 220 "    LDR     R3, =current_write_ignored\n"
 221 "    LDR     R3, [R3]\n"
 222 "    CMP     R3, #0\n"
 223 "    BNE     loc_A\n" // jump over the next block
 224 //mod end
 225 "    LDR     R1, [R4, #8] \n"
 226 "    MOV     R0, R5 \n"
 227 "    BL      sub_FF02130C \n"
 228 "    CMP     R0, #0 \n"
 229 "    MOVEQ   R1, R4 \n"
 230 "    MOVEQ   R0, #7 \n"
 231 "    BEQ     loc_FF2FB258 \n"
 232 
 233 "loc_FF2FB234:\n"
 234 "loc_A:\n"
 235 "    LDR     R0, [R4, #0x50] \n"
 236 "    CMP     R0, #2 \n"
 237 "    BEQ     loc_FF2FB250 \n"
 238 "    LDR     R0, [R4, #4] \n"
 239 "    CMP     R0, #0 \n"
 240 "    MOVEQ   R1, R4 \n"
 241 "    BEQ     loc_FF2FB258 \n"
 242 
 243 "loc_FF2FB250:\n"
 244 "    MOV     R1, R4 \n"
 245 "    MOV     R0, #9 \n"
 246 
 247 "loc_FF2FB258:\n"
 248 "    BL      sub_FF2FB03C \n"
 249 
 250 "loc_FF2FB25C:\n"
 251 "    ADD     SP, SP, #0x3C \n"
 252 "    LDMFD   SP!, {R4-R9,PC} \n"
 253 );
 254 }
 255 
 256 /*************************************************************/
 257 //** sub_FF2FB738_my @ 0xFF2FB738 - 0xFF2FB814, length=56
 258 void __attribute__((naked,noinline)) sub_FF2FB738_my() {
 259 asm volatile (
 260 "    STMFD   SP!, {R4-R10,LR} \n"
 261 "    MOV     R5, R0 \n"
 262 "    LDR     R0, [R0] \n"
 263 "    CMP     R0, #6 \n"
 264 "    BHI     loc_FF2FB764 \n"
 265 "    ADD     R0, R5, R0, LSL#3 \n"
 266 "    LDR     R8, [R0, #0x18]! \n"
 267 "    LDR     R7, [R0, #4] \n"
 268 "    CMP     R7, #0 \n"
 269 "    BNE     loc_FF2FB77C \n"
 270 "    B       loc_FF2FB770 \n"
 271 
 272 "loc_FF2FB764:\n"
 273 "    LDR     R1, =0x2DD \n"
 274 "    LDR     R0, =0xFF2FB540 /*'dwFWrite.c'*/ \n"
 275 "    BL      _DebugAssert \n"
 276 
 277 "loc_FF2FB770:\n"
 278 "    MOV     R1, R5 \n"
 279 "    MOV     R0, #7 \n"
 280 "    B       loc_FF2FB810 \n"
 281 
 282 "loc_FF2FB77C:\n"
 283 "    LDR     R9, =0xE704 \n"
 284 "    MOV     R4, R7 \n"
 285 
 286 "loc_FF2FB784:\n"
 287 "    LDR     R0, [R5, #4] \n"
 288 "    CMP     R4, #0x1000000 \n"
 289 "    MOVLS   R6, R4 \n"
 290 "    MOVHI   R6, #0x1000000 \n"
 291 "    BIC     R1, R0, #0xFF000000 \n"
 292 "    CMP     R1, #0 \n"
 293 "    BICNE   R0, R0, #0xFF000000 \n"
 294 "    RSBNE   R0, R0, #0x1000000 \n"
 295 "    CMPNE   R6, R0 \n"
 296 "    MOVHI   R6, R0 \n"
 297 "    LDR     R0, [R9, #8] \n"
 298 "    MOV     R2, R6 \n"
 299 "    MOV     R1, R8 \n"
 300 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 301 "    LDR     R1, [R5, #4] \n"
 302 "    CMP     R6, R0 \n"
 303 "    ADD     R1, R1, R0 \n"
 304 "    STR     R1, [R5, #4] \n"
 305 "    BEQ     loc_FF2FB7E4 \n"
 306 "    CMN     R0, #1 \n"
 307 "    LDRNE   R0, =0x9200015 \n"
 308 "    LDREQ   R0, =0x9200005 \n"
 309 "    STR     R0, [R5, #0x14] \n"
 310 "    B       loc_FF2FB770 \n"
 311 
 312 "loc_FF2FB7E4:\n"
 313 "    SUB     R4, R4, R0 \n"
 314 "    CMP     R4, R7 \n"
 315 "    ADD     R8, R8, R0 \n"
 316 "    MOVCS   R1, #0x308 \n"
 317 "    LDRCS   R0, =0xFF2FB540 /*'dwFWrite.c'*/ \n"
 318 "    BLCS    _DebugAssert \n"
 319 "    CMP     R4, #0 \n"
 320 "    BNE     loc_FF2FB784 \n"
 321 "    LDR     R0, [R5] \n"
 322 "    MOV     R1, R5 \n"
 323 "    ADD     R0, R0, #1 \n"
 324 
 325 "loc_FF2FB810:\n"
 326 "    LDMFD   SP!, {R4-R10,LR} \n"
 327 "    B       sub_FF2FB03C \n"
 328 );
 329 }
 330 
 331 /*************************************************************/
 332 //** sub_FF2FB264_my @ 0xFF2FB264 - 0xFF2FB3F8, length=102
 333 void __attribute__((naked,noinline)) sub_FF2FB264_my() {
 334 asm volatile (
 335 "    STMFD   SP!, {R4-R6,LR} \n"
 336 "    MOV     R4, R0 \n"
 337 "    LDR     R0, [R0, #0x50] \n"
 338 "    LDR     R5, =0xE704 \n"
 339 "    CMP     R0, #3 \n"
 340 "    SUB     SP, SP, #0x38 \n"
 341 "    BEQ     loc_FF2FB3DC \n"
 342 "    LDR     R0, [R5, #8] \n"
 343 "    CMN     R0, #1 \n"
 344 "    BEQ     loc_FF2FB2B8 \n"
 345 "    LDR     R1, [R4, #0xC] \n"
 346 "    LDR     R6, =0x9200003 \n"
 347 "    TST     R1, #0x8000 \n"
 348 "    BEQ     loc_FF2FB2A4 \n"
 349 //mod start
 350 "    LDR     R3, =current_write_ignored\n"
 351 "    LDR     R3, [R3]\n"
 352 "    CMP     R3, #0\n"
 353 "    BNE     loc_B\n" // jump over the next block
 354 //mod end
 355 "    BL      sub_FF021038 \n"
 356 "    B       loc_FF2FB2A8 \n"
 357 
 358 "loc_FF2FB2A4:\n"
 359 "loc_B:\n"
 360 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 361 
 362 "loc_FF2FB2A8:\n"
 363 "    CMP     R0, #0 \n"
 364 "    MVN     R0, #0 \n"
 365 "    STRNE   R6, [R4, #0x14] \n"
 366 "    STR     R0, [R5, #8] \n"
 367 
 368 "loc_FF2FB2B8:\n"
 369 "    LDR     R0, [R4, #0x14] \n"
 370 "    TST     R0, #1 \n"
 371 "    BNE     loc_FF2FB3C0 \n"
 372 "    LDR     R0, [R4, #0xC] \n"
 373 "    TST     R0, #8 \n"
 374 "    BNE     loc_FF2FB2DC \n"
 375 "    LDR     R0, [R4, #0x50] \n"
 376 "    CMP     R0, #3 \n"
 377 "    BNE     loc_FF2FB30C \n"
 378 
 379 "loc_FF2FB2DC:\n"
 380 "    ADD     R1, SP, #0x20 \n"
 381 "    ADD     R0, R4, #0x54 \n"
 382 "    BL      sub_FF059A6C \n"
 383 "    CMP     R0, #0 \n"
 384 "    LDREQ   R1, =0x346 \n"
 385 "    LDREQ   R0, =0xFF2FB540 /*'dwFWrite.c'*/ \n"
 386 "    BLEQ    _DebugAssert \n"
 387 "    LDR     R0, [SP, #0x28] \n"
 388 "    LDR     R1, [R4, #4] \n"
 389 "    ADD     R0, R0, R1 \n"
 390 "    STR     R0, [SP, #0x28] \n"
 391 "    B       loc_FF2FB33C \n"
 392 
 393 "loc_FF2FB30C:\n"
 394 "    LDR     R0, =0x81FF \n"
 395 "    STR     R0, [SP, #0x20] \n"
 396 "    MOV     R0, #0x20 \n"
 397 "    STR     R0, [SP, #0x24] \n"
 398 "    LDR     R0, [R4, #4] \n"
 399 "    STR     R0, [SP, #0x28] \n"
 400 "    LDR     R0, [R4, #0x10] \n"
 401 "    STR     R0, [SP, #0x2C] \n"
 402 "    LDR     R0, [R4, #0x10] \n"
 403 "    STR     R0, [SP, #0x30] \n"
 404 "    LDR     R0, [R4, #0x10] \n"
 405 "    STR     R0, [SP, #0x34] \n"
 406 
 407 "loc_FF2FB33C:\n"
 408 "    LDR     R0, [R4, #0x50] \n"
 409 "    CMP     R0, #2 \n"
 410 "    BEQ     loc_FF2FB3C0 \n"
 411 "    ADD     R1, SP, #0x20 \n"
 412 "    ADD     R0, R4, #0x54 \n"
 413 "    BL      sub_FF059B24 \n"
 414 "    LDR     R0, [R4, #0x50] \n"
 415 "    CMP     R0, #1 \n"
 416 "    BNE     loc_FF2FB3C0 \n"
 417 "    MOV     R2, #0x20 \n"
 418 "    ADD     R1, R4, #0x54 \n"
 419 "    MOV     R0, SP \n"
 420 "    BL      sub_00690364 \n"
 421 "    MOV     R0, SP \n"
 422 "    BL      _strlen \n"
 423 "    MOV     R2, #0x54 \n"
 424 "    ADD     R0, R0, SP \n"
 425 "    MOV     R1, #0x4D \n"
 426 "    STRB    R2, [R0, #-3] \n"
 427 "    STRB    R1, [R0, #-2] \n"
 428 "    MOV     R1, #0x50 \n"
 429 "    STRB    R1, [R0, #-1] \n"
 430 "    MOV     R1, SP \n"
 431 "    ADD     R0, R4, #0x54 \n"
 432 "    BL      sub_FF0593BC \n"
 433 "    CMP     R0, #0 \n"
 434 "    MOVEQ   R1, #0x164 \n"
 435 "    LDREQ   R0, =0xFF2FB540 /*'dwFWrite.c'*/ \n"
 436 "    BLEQ    _DebugAssert \n"
 437 "    MOV     R0, SP \n"
 438 "    BL      sub_FF059F80 \n"
 439 "    ADD     R0, R4, #0x54 \n"
 440 "    BL      sub_FF059F80 \n"
 441 
 442 "loc_FF2FB3C0:\n"
 443 "    ADD     R0, R4, #0x54 \n"
 444 "    BL      sub_FF05C27C \n"
 445 "    LDR     R1, [R5, #0x1C] \n"
 446 "    BL      sub_FF05A2E4 \n"
 447 "    MOV     R0, #0 \n"
 448 "    STR     R0, [R5, #4] \n"
 449 "    B       loc_FF2FB3E4 \n"
 450 
 451 "loc_FF2FB3DC:\n"
 452 "    LDR     R0, [R5, #0x1C] \n"
 453 "    BLX     R0 \n"
 454 
 455 "loc_FF2FB3E4:\n"
 456 "    LDR     R1, [R5, #0x18] \n"
 457 "    CMP     R1, #0 \n"
 458 "    LDRNE   R0, [R4, #0x14] \n"
 459 "    BLXNE   R1 \n"
 460 "    ADD     SP, SP, #0x38 \n"
 461 "    LDMFD   SP!, {R4-R6,PC} \n"
 462 );
 463 }

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