root/platform/ixus145_elph135/sub/100c/filewrite.c

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFAA8F88_my
  3. sub_FFAA9668_my
  4. sub_FFAA9120_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 
  15 /*
  16  * fwt_data_struct: defined here as it's camera dependent
  17  * unneeded members are designated with unkn
  18  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  19  * pdc is always required
  20  * name is not currently used
  21  */
  22 typedef struct
  23 {
  24     int unkn1;
  25     int file_offset;
  26     int full_size;
  27     int unkn2, unkn3;
  28     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_JPEG];
  29     int seek_flag;      // offset from start 0x4c = 76 bytes = 19 words
  30     int unkn4, unkn5;
  31     char name[32];      // offset from start 0x58 = 88 bytes = 22 words
  32 } fwt_data_struct;
  33 // seek_flag is different:
  34 // seek state is activated (from state 0xc, open) when
  35 // (word at 0x4c) AND 0x40
  36 // OR
  37 // write offset is not 0
  38 #define FWT_MUSTSEEK    0x40   // value of the masked seek_flag indicating seek is required
  39 #define FWT_SEEKMASK    0x40   // masks out unneeded bits of seek_flag
  40 
  41 #include "../../../generic/filewrite.c"
  42 
  43 /*************************************************************/
  44 //** filewritetask @ 0xFFAA92A8 - 0xFFAA944C, length=106
  45 void __attribute__((naked,noinline)) filewritetask() {
  46 asm volatile (
  47 "    STMFD   SP!, {R1-R7,LR} \n"
  48 "    LDR     R5, =0xB1CC \n"
  49 "    MOV     R6, #0 \n"
  50 
  51 "loc_FFAA92B4:\n"
  52 "    LDR     R0, [R5, #0x10] \n"
  53 "    MOV     R2, #0 \n"
  54 "    ADD     R1, SP, #8 \n"
  55 "    BL      sub_006B8458 /*_ReceiveMessageQueue*/ \n"
  56 "    CMP     R0, #0 \n"
  57 "    LDRNE   R2, =0x3F5 \n"
  58 "    LDRNE   R1, =0xFFAA9474 /*'dwFWrite.c'*/ \n"
  59 "    MOVNE   R0, #0 \n"
  60 "    BLNE    _DebugAssert \n"
  61 "    LDR     R0, [SP, #8] \n"
  62 "    LDR     R1, [R0] \n"
  63 "    CMP     R1, #0xD \n"
  64 "    ADDCC   PC, PC, R1, LSL#2 \n"
  65 "    B       loc_FFAA92B4 \n"
  66 "    B       loc_FFAA9440 \n"
  67 "    B       loc_FFAA9440 \n"
  68 "    B       loc_FFAA9440 \n"
  69 "    B       loc_FFAA9440 \n"
  70 "    B       loc_FFAA9440 \n"
  71 "    B       loc_FFAA9440 \n"
  72 "    B       loc_FFAA9440 \n"
  73 "    B       loc_FFAA9448 \n"
  74 "    B       loc_FFAA9320 \n"
  75 "    B       loc_FFAA93BC \n"
  76 "    B       loc_FFAA93EC \n"
  77 "    B       loc_FFAA9388 \n"
  78 "    B       loc_FFAA93B4 \n"
  79 
  80 "loc_FFAA9320:\n"
  81 "    MOV     R4, R5 \n"
  82 "    STR     R6, [SP] \n"
  83 
  84 "loc_FFAA9328:\n"
  85 "    LDR     R0, [R4, #0x10] \n"
  86 "    MOV     R1, SP \n"
  87 "    BL      sub_006B86D4 /*_GetNumberOfPostedMessages*/ \n"
  88 "    LDR     R0, [SP] \n"
  89 "    CMP     R0, #0 \n"
  90 "    BEQ     loc_FFAA9354 \n"
  91 "    LDR     R0, [R4, #0x10] \n"
  92 "    MOV     R2, #0 \n"
  93 "    ADD     R1, SP, #4 \n"
  94 "    BL      sub_006B8458 /*_ReceiveMessageQueue*/ \n"
  95 "    B       loc_FFAA9328 \n"
  96 
  97 "loc_FFAA9354:\n"
  98 "    LDR     R0, [R4, #4] \n"
  99 "    CMN     R0, #1 \n"
 100 "    BEQ     fwt_close \n"  // --> Patched. Old value = 0xFFAA937C.
 101 "    BL      _Close \n"
 102 "    MVN     R0, #0 \n"
 103 "    STR     R0, [R4, #4] \n"
 104 "    LDR     R0, =0xFAEA4 \n"
 105 "    BL      sub_FF830358 \n"
 106 "    MOV     R1, #0 \n"
 107 "    BL      sub_FF82E1CC \n"
 108 
 109 "loc_FFAA937C:\n"
 110 "    LDR     R0, [R4, #0xC] \n"
 111 "    BL      _GiveSemaphore \n"
 112 "    B       loc_FFAA92B4 \n"
 113 
 114 "loc_FFAA9388:\n"
 115 "    MOV     R4, R0 \n"
 116 "    ADD     R0, R0, #0x58 \n"
 117 "    BL      sub_FF830358 \n"
 118 "    MOV     R1, #0 \n"
 119 "    BL      sub_FF82E08C \n"
 120 "    LDR     R0, [R4, #0xC] \n"
 121 "    BL      sub_FF82D128 \n"
 122 "    ADD     R0, R4, #0x58 \n"
 123 
 124 //mod start
 125 "    LDR R3, =ignore_current_write\n" // !!
 126 "    LDR R3, [R3]\n"
 127 "    CMP R3, #0\n"
 128 "    BNE loc_A\n" // skip creating directory
 129 //mod end
 130 "    BL      sub_FF8277FC \n"
 131 "    ADD     R0, R4, #0x58 \n"
 132 "    B       loc_FFAA9420 \n"
 133 
 134 "loc_FFAA93B4:\n"
 135 "    BL      sub_FFAA8F88_my \n"  // --> Patched. Old value = 0xFFAA8F88. Open stage
 136 "    B       loc_FFAA92B4 \n"
 137 
 138 "loc_FFAA93BC:\n"
 139 "    LDR     R1, [R0, #4] \n"
 140 "    MOV     R4, R0 \n"
 141 "    LDR     R0, [R5, #4] \n"
 142 "    MOV     R2, #0 \n"
 143 "    BL      fwt_lseek \n"  // --> Patched. Old value = _lseek.
 144 "    CMN     R0, #1 \n"
 145 "    LDREQ   R0, =0x9200013 \n"
 146 "    MOVEQ   R1, R4 \n"
 147 "    STREQ   R0, [R4, #0x10] \n"
 148 "    MOVEQ   R0, #7 \n"
 149 "    BLEQ    sub_FFAA8EC8 \n"
 150 "    B       loc_FFAA92B4 \n"
 151 
 152 "loc_FFAA93EC:\n"
 153 "    MOV     R4, R0 \n"
 154 "    LDRSB   R0, [R0, #0x58] \n"
 155 "    CMP     R0, #0 \n"
 156 "    BEQ     loc_FFAA92B4 \n"
 157 "    STRB    R0, [SP, #4] \n"
 158 "    ADD     R0, R4, #0x58 \n"
 159 "    STRB    R6, [SP, #5] \n"
 160 "    BL      sub_FF830358 \n"
 161 "    MOV     R1, #0 \n"
 162 "    BL      sub_FF82E08C \n"
 163 
 164 //mod start
 165 "    LDR R3, =ignore_current_write\n" // !!
 166 "    LDR R3, [R3]\n"
 167 "    CMP R3, #0\n"
 168 "    BNE loc_B\n" // skip flushing the cache
 169 //mod end
 170 
 171 "    ADD     R0, SP, #4 \n"
 172 "    BL      sub_FF82D140 \n"
 173 "loc_B:\n"
 174 "    ADD     R0, R4, #0x58 \n"
 175 
 176 "loc_FFAA9420:\n"
 177 "loc_A:\n"
 178 "    BL      sub_FF830358 \n"
 179 "    LDR     R1, [R5, #0x1C] \n"
 180 "    BL      sub_FF82E1CC \n"
 181 "    LDR     R1, [R5, #0x14] \n"
 182 "    CMP     R1, #0 \n"
 183 "    LDRNE   R0, [R4, #0x10] \n"
 184 "    BLXNE   R1 \n"
 185 "    B       loc_FFAA92B4 \n"
 186 
 187 "loc_FFAA9440:\n"
 188 "    BL      sub_FFAA9668_my \n"  // --> Patched. Old value = 0xFFAA9668. Write stage
 189 "    B       loc_FFAA92B4 \n"
 190 
 191 "loc_FFAA9448:\n"
 192 "    BL      sub_FFAA9120_my \n"  // --> Patched. Old value = 0xFFAA9120. Close stage
 193 "    B       loc_FFAA92B4 \n"
 194 );
 195 }
 196 
 197 /*************************************************************/
 198 //** sub_FFAA8F88_my @ 0xFFAA8F88 - 0xFFAA911C, length=102
 199 void __attribute__((naked,noinline)) sub_FFAA8F88_my() {
 200 asm volatile (
 201 "    STMFD   SP!, {R4-R9,LR} \n"
 202 "    MOV     R4, R0 \n"
 203 //hook placed here to avoid conditional branch a few instructions below (watch out for registers!)
 204 //"  MOV   R0, R4\n"      //data block start, commented out as R0 is already holding what we need
 205 "    BL filewrite_main_hook\n"
 206 "    MOV     R0, R4\n"      //restore register(s)
 207 //hook end
 208 "    LDR     R0, [R0, #0x4C] \n"
 209 "    SUB     SP, SP, #0x3C \n"
 210 "    TST     R0, #1 \n"
 211 "    BEQ     loc_FFAA90F0 \n"
 212 "    LDR     R7, =0xB1CC \n"
 213 "    LDR     R0, [R7, #0x18] \n"
 214 "    CMP     R0, #0 \n"
 215 "    BLXNE   R0 \n"
 216 "    ADD     R0, R4, #0x58 \n"
 217 "    BL      sub_FF830358 \n"
 218 "    MOV     R1, #0 \n"
 219 "    BL      sub_FF82E08C \n"
 220 "    LDR     R0, [R4, #0xC] \n"
 221 "    BL      sub_FF82D128 \n"
 222 "    LDR     R0, [R4, #0x4C] \n"
 223 "    LDR     R5, =0x301 \n"
 224 "    TST     R0, #0x10 \n"
 225 "    MOVNE   R5, #9 \n"
 226 "    BNE     loc_FFAA8FE4 \n"
 227 "    TST     R0, #0x40 \n"
 228 "    MOVNE   R5, #1 \n"
 229 
 230 "loc_FFAA8FE4:\n"
 231 "    TST     R0, #0x20 \n"
 232 "    BNE     loc_FFAA8FF8 \n"
 233 "    LDR     R0, [R4, #0x54] \n"
 234 "    CMP     R0, #1 \n"
 235 "    BNE     loc_FFAA8FFC \n"
 236 
 237 "loc_FFAA8FF8:\n"
 238 "    ORR     R5, R5, #0x8000 \n"
 239 
 240 "loc_FFAA8FFC:\n"
 241 "    LDR     R9, =0x1B6 \n"
 242 "    ADD     R8, R4, #0x58 \n"
 243 "    LDR     R6, [R4, #0xC] \n"
 244 "    MOV     R2, R9 \n"
 245 "    MOV     R1, R5 \n"
 246 "    MOV     R0, R8 \n"
 247 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 248 "    CMN     R0, #1 \n"
 249 "    BNE     loc_FFAA907C \n"
 250 "    MOV     R0, R8 \n"
 251 "    BL      sub_FF8277FC \n"
 252 "    MOV     R2, #0xF \n"
 253 "    MOV     R1, R8 \n"
 254 "    ADD     R0, SP, #4 \n"
 255 "    BL      sub_006BCD9C \n"
 256 "    MOV     R0, #0 \n"
 257 "    LDR     R1, =0x41FF \n"
 258 "    STRB    R0, [SP, #0x13] \n"
 259 "    STR     R1, [SP, #0x24] \n"
 260 "    MOV     R1, #0x10 \n"
 261 "    STR     R0, [SP, #0x2C] \n"
 262 "    STR     R1, [SP, #0x28] \n"
 263 "    ADD     R1, SP, #0x24 \n"
 264 "    ADD     R0, SP, #4 \n"
 265 "    STR     R6, [SP, #0x30] \n"
 266 "    STR     R6, [SP, #0x34] \n"
 267 "    STR     R6, [SP, #0x38] \n"
 268 "    BL      sub_FF82D9F0 \n"
 269 "    MOV     R2, R9 \n"
 270 "    MOV     R1, R5 \n"
 271 "    MOV     R0, R8 \n"
 272 "    BL      _Open \n"
 273 
 274 "loc_FFAA907C:\n"
 275 "    CMN     R0, #1 \n"
 276 "    MOV     R5, R0 \n"
 277 "    STR     R0, [R7, #4] \n"
 278 "    BNE     loc_FFAA90B8 \n"
 279 "    ADD     R0, R4, #0x58 \n"
 280 "    BL      sub_FF830358 \n"
 281 "    LDR     R1, [R7, #0x1C] \n"
 282 "    BL      sub_FF82E1CC \n"
 283 "    LDR     R1, [R7, #0x14] \n"
 284 "    CMP     R1, #0 \n"
 285 "    BEQ     loc_FFAA9118 \n"
 286 "    ADD     SP, SP, #0x3C \n"
 287 "    LDMFD   SP!, {R4-R9,LR} \n"
 288 "    LDR     R0, =0x9200001 \n"
 289 "    BX      R1 \n"
 290 
 291 "loc_FFAA90B8:\n"
 292 "    LDR     R0, =0xFAEA4 \n"
 293 "    MOV     R2, #0x20 \n"
 294 "    ADD     R1, R4, #0x58 \n"
 295 "    BL      sub_006BCF84 \n"
 296 
 297 //mod start
 298 "    LDR R3, =current_write_ignored\n"
 299 "    LDR R3, [R3]\n"
 300 "    CMP R3, #0\n"
 301 "    BNE loc_C\n" // jump over the next block
 302 //mod end
 303 
 304 "    LDR     R0, [R4, #0x4C] \n"
 305 "    TST     R0, #0x80 \n"
 306 "    BEQ     loc_FFAA90F0 \n"
 307 "    LDR     R1, [R4, #8] \n"
 308 "    MOV     R0, R5 \n"
 309 "    BL      sub_FF8274CC \n"
 310 "    CMP     R0, #0 \n"
 311 "    MOVEQ   R1, R4 \n"
 312 "    MOVEQ   R0, #7 \n"
 313 "    BEQ     loc_FFAA9114 \n"
 314 
 315 "loc_FFAA90F0:\n"
 316 "loc_C:\n"
 317 "    LDR     R0, [R4, #0x4C] \n"
 318 "    TST     R0, #0x40 \n"
 319 "    LDREQ   R0, [R4, #4] \n"
 320 "    CMPEQ   R0, #0 \n"
 321 "    MOVNE   R1, R4 \n"
 322 "    MOVNE   R0, #9 \n"
 323 "    BLNE    sub_FFAA8EC8 \n"
 324 "    MOV     R1, R4 \n"
 325 "    MOV     R0, #0 \n"
 326 
 327 "loc_FFAA9114:\n"
 328 "    BL      sub_FFAA8EC8 \n"
 329 
 330 "loc_FFAA9118:\n"
 331 "    ADD     SP, SP, #0x3C \n"
 332 "    LDMFD   SP!, {R4-R9,PC} \n"
 333 );
 334 }
 335 
 336 /*************************************************************/
 337 //** sub_FFAA9668_my @ 0xFFAA9668 - 0xFFAA974C, length=58
 338 void __attribute__((naked,noinline)) sub_FFAA9668_my() {
 339 asm volatile (
 340 "    STMFD   SP!, {R4-R10,LR} \n"
 341 "    MOV     R5, R0 \n"
 342 "    LDR     R0, [R0] \n"
 343 "    CMP     R0, #6 \n"
 344 "    BHI     loc_FFAA9694 \n"
 345 "    ADD     R0, R5, R0, LSL#3 \n"
 346 "    LDR     R8, [R0, #0x14]! \n"
 347 "    LDR     R7, [R0, #4] \n"
 348 "    CMP     R7, #0 \n"
 349 "    BNE     loc_FFAA96B0 \n"
 350 "    B       loc_FFAA96A4 \n"
 351 
 352 "loc_FFAA9694:\n"
 353 "    LDR     R2, =0x34A \n"
 354 "    LDR     R1, =0xFFAA9474 /*'dwFWrite.c'*/ \n"
 355 "    MOV     R0, #0 \n"
 356 "    BL      _DebugAssert \n"
 357 
 358 "loc_FFAA96A4:\n"
 359 "    MOV     R1, R5 \n"
 360 "    MOV     R0, #7 \n"
 361 "    B       loc_FFAA9748 \n"
 362 
 363 "loc_FFAA96B0:\n"
 364 "    LDR     R9, =0xB1CC \n"
 365 "    MOV     R4, R7 \n"
 366 
 367 "loc_FFAA96B8:\n"
 368 "    LDR     R0, [R5, #4] \n"
 369 "    CMP     R4, #0x1000000 \n"
 370 "    MOVLS   R6, R4 \n"
 371 "    MOVHI   R6, #0x1000000 \n"
 372 "    BIC     R1, R0, #0xFF000000 \n"
 373 "    CMP     R1, #0 \n"
 374 "    BICNE   R0, R0, #0xFF000000 \n"
 375 "    RSBNE   R0, R0, #0x1000000 \n"
 376 "    CMPNE   R6, R0 \n"
 377 "    MOVHI   R6, R0 \n"
 378 "    LDR     R0, [R9, #4] \n"
 379 "    MOV     R2, R6 \n"
 380 "    MOV     R1, R8 \n"
 381 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 382 "    LDR     R1, [R5, #4] \n"
 383 "    CMP     R6, R0 \n"
 384 "    ADD     R1, R1, R0 \n"
 385 "    STR     R1, [R5, #4] \n"
 386 "    BEQ     loc_FFAA9718 \n"
 387 "    CMN     R0, #1 \n"
 388 "    LDRNE   R0, =0x9200015 \n"
 389 "    LDREQ   R0, =0x9200005 \n"
 390 "    STR     R0, [R5, #0x10] \n"
 391 "    B       loc_FFAA96A4 \n"
 392 
 393 "loc_FFAA9718:\n"
 394 "    SUB     R4, R4, R0 \n"
 395 "    CMP     R4, R7 \n"
 396 "    LDRCS   R2, =0x375 \n"
 397 "    ADD     R8, R8, R0 \n"
 398 "    LDRCS   R1, =0xFFAA9474 /*'dwFWrite.c'*/ \n"
 399 "    MOVCS   R0, #0 \n"
 400 "    BLCS    _DebugAssert \n"
 401 "    CMP     R4, #0 \n"
 402 "    BNE     loc_FFAA96B8 \n"
 403 "    LDR     R0, [R5] \n"
 404 "    MOV     R1, R5 \n"
 405 "    ADD     R0, R0, #1 \n"
 406 
 407 "loc_FFAA9748:\n"
 408 "    LDMFD   SP!, {R4-R10,LR} \n"
 409 "    B       sub_FFAA8EC8 \n"
 410 "    .ltorg\n" //+
 411 );
 412 }
 413 
 414 /*************************************************************/
 415 //** sub_FFAA9120_my @ 0xFFAA9120 - 0xFFAA9160, length=17
 416 void __attribute__((naked,noinline)) sub_FFAA9120_my() {
 417 asm volatile (
 418 "    STMFD   SP!, {R4-R6,LR} \n"
 419 "    MOV     R4, R0 \n"
 420 "    LDR     R0, [R0, #0x4C] \n"
 421 "    LDR     R5, =0xB1CC \n"
 422 "    TST     R0, #2 \n"
 423 "    SUB     SP, SP, #0x38 \n"
 424 "    BEQ     sub_FFAA9288 \n"
 425 "    LDR     R0, [R5, #4] \n"
 426 "    CMN     R0, #1 \n"
 427 "    BEQ     sub_FFAA9174 \n"
 428 "    LDR     R1, [R4, #0x54] \n"
 429 "    LDR     R6, =0x9200003 \n"
 430 "    CMP     R1, #1 \n"
 431 "    BNE     loc_FFAA9160 \n"
 432 //mod start
 433 "    LDR R3, =current_write_ignored\n"
 434 "    LDR R3, [R3]\n"
 435 "    CMP R3, #0\n"
 436 "    BNE loc_D\n" // jump over the next block
 437 //mod end
 438 
 439 "    BL      sub_FF827220 \n"
 440 "    B       sub_FFAA9164 \n"
 441 
 442 "loc_FFAA9160:\n"
 443 "loc_D:\n"
 444 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 445 "    LDR     PC, =0xFFAA9164 \n"  // Continue in firmware
 446 );
 447 }

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