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

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFAA2234_my
  3. sub_FFAA2914_my
  4. sub_FFAA23CC_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 /*************************************************************/
  45 //** filewritetask @ 0xFFAA2554 - 0xFFAA26F8, length=106
  46 void __attribute__((naked,noinline)) filewritetask() {
  47 asm volatile (
  48 "    STMFD   SP!, {R1-R7,LR} \n"
  49 "    LDR     R5, =0xB460 \n"
  50 "    MOV     R6, #0 \n"
  51 
  52 "loc_FFAA2560:\n"
  53 "    LDR     R0, [R5, #0x10] \n"
  54 "    MOV     R2, #0 \n"
  55 "    ADD     R1, SP, #8 \n"
  56 "    BL      sub_006B8458 /*_ReceiveMessageQueue*/ \n"
  57 "    CMP     R0, #0 \n"
  58 "    LDRNE   R2, =0x3F5 \n"
  59 "    LDRNE   R1, =0xFFAA2720 /*'dwFWrite.c'*/ \n"
  60 "    MOVNE   R0, #0 \n"
  61 "    BLNE    _DebugAssert \n"
  62 "    LDR     R0, [SP, #8] \n"
  63 "    LDR     R1, [R0] \n"
  64 "    CMP     R1, #0xD \n"
  65 "    ADDCC   PC, PC, R1, LSL#2 \n"
  66 "    B       loc_FFAA2560 \n"
  67 "    B       loc_FFAA26EC \n"
  68 "    B       loc_FFAA26EC \n"
  69 "    B       loc_FFAA26EC \n"
  70 "    B       loc_FFAA26EC \n"
  71 "    B       loc_FFAA26EC \n"
  72 "    B       loc_FFAA26EC \n"
  73 "    B       loc_FFAA26EC \n"
  74 "    B       loc_FFAA26F4 \n"
  75 "    B       loc_FFAA25CC \n"
  76 "    B       loc_FFAA2668 \n"
  77 "    B       loc_FFAA2698 \n"
  78 "    B       loc_FFAA2634 \n"
  79 "    B       loc_FFAA2660 \n"
  80 
  81 "loc_FFAA25CC:\n"
  82 "    MOV     R4, R5 \n"
  83 "    STR     R6, [SP] \n"
  84 
  85 "loc_FFAA25D4:\n"
  86 "    LDR     R0, [R4, #0x10] \n"
  87 "    MOV     R1, SP \n"
  88 "    BL      sub_006B86D4 /*_GetNumberOfPostedMessages*/ \n"
  89 "    LDR     R0, [SP] \n"
  90 "    CMP     R0, #0 \n"
  91 "    BEQ     loc_FFAA2600 \n"
  92 "    LDR     R0, [R4, #0x10] \n"
  93 "    MOV     R2, #0 \n"
  94 "    ADD     R1, SP, #4 \n"
  95 "    BL      sub_006B8458 /*_ReceiveMessageQueue*/ \n"
  96 "    B       loc_FFAA25D4 \n"
  97 
  98 "loc_FFAA2600:\n"
  99 "    LDR     R0, [R4, #4] \n"
 100 "    CMN     R0, #1 \n"
 101 "    BEQ     loc_FFAA2628 \n"
 102 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 103 "    MVN     R0, #0 \n"
 104 "    STR     R0, [R4, #4] \n"
 105 "    LDR     R0, =0xFC318 \n"
 106 "    BL      sub_FF830358 \n"
 107 "    MOV     R1, #0 \n"
 108 "    BL      sub_FF82E1CC \n"
 109 
 110 "loc_FFAA2628:\n"
 111 "    LDR     R0, [R4, #0xC] \n"
 112 "    BL      _GiveSemaphore \n"
 113 "    B       loc_FFAA2560 \n"
 114 
 115 "loc_FFAA2634:\n"
 116 "    MOV     R4, R0 \n"
 117 "    ADD     R0, R0, #0x58 \n"
 118 "    BL      sub_FF830358 \n"
 119 "    MOV     R1, #0 \n"
 120 "    BL      sub_FF82E08C \n"
 121 "    LDR     R0, [R4, #0xC] \n"
 122 "    BL      sub_FF82D128 \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 "    ADD     R0, R4, #0x58 \n"
 131 "    BL      sub_FF8277FC \n"
 132 "loc_A:\n"
 133 "    ADD     R0, R4, #0x58 \n"
 134 "    B       loc_FFAA26CC \n"
 135 
 136 "loc_FFAA2660:\n"
 137 "    BL      sub_FFAA2234_my \n"  // --> Patched. Old value = 0xFFAA2234. Open stage
 138 "    B       loc_FFAA2560 \n"
 139 
 140 "loc_FFAA2668:\n"
 141 "    LDR     R1, [R0, #4] \n"
 142 "    MOV     R4, R0 \n"
 143 "    LDR     R0, [R5, #4] \n"
 144 "    MOV     R2, #0 \n"
 145 "    BL      fwt_lseek \n"  // --> Patched. Old value = _lseek.
 146 "    CMN     R0, #1 \n"
 147 "    LDREQ   R0, =0x9200013 \n"
 148 "    MOVEQ   R1, R4 \n"
 149 "    STREQ   R0, [R4, #0x10] \n"
 150 "    MOVEQ   R0, #7 \n"
 151 "    BLEQ    sub_FFAA2174 \n"
 152 "    B       loc_FFAA2560 \n"
 153 
 154 "loc_FFAA2698:\n"
 155 "    MOV     R4, R0 \n"
 156 "    LDRSB   R0, [R0, #0x58] \n"
 157 "    CMP     R0, #0 \n"
 158 "    BEQ     loc_FFAA2560 \n"
 159 "    STRB    R0, [SP, #4] \n"
 160 "    ADD     R0, R4, #0x58 \n"
 161 "    STRB    R6, [SP, #5] \n"
 162 "    BL      sub_FF830358 \n"
 163 "    MOV     R1, #0 \n"
 164 "    BL      sub_FF82E08C \n"
 165 
 166 //mod start
 167 "    LDR R3, =ignore_current_write\n" // !!
 168 "    LDR R3, [R3]\n"
 169 "    CMP R3, #0\n"
 170 "    BNE loc_B\n" // skip flushing the cache
 171 //mod end
 172 
 173 "    ADD     R0, SP, #4 \n"
 174 "    BL      sub_FF82D140 \n"
 175 "loc_B:\n"
 176 "    ADD     R0, R4, #0x58 \n"
 177 
 178 "loc_FFAA26CC:\n"
 179 "    BL      sub_FF830358 \n"
 180 "    LDR     R1, [R5, #0x1C] \n"
 181 "    BL      sub_FF82E1CC \n"
 182 "    LDR     R1, [R5, #0x14] \n"
 183 "    CMP     R1, #0 \n"
 184 "    LDRNE   R0, [R4, #0x10] \n"
 185 "    BLXNE   R1 \n"
 186 "    B       loc_FFAA2560 \n"
 187 
 188 "loc_FFAA26EC:\n"
 189 "    BL      sub_FFAA2914_my \n"  // --> Patched. Old value = 0xFFAA2914. Write stage
 190 "    B       loc_FFAA2560 \n"
 191 
 192 "loc_FFAA26F4:\n"
 193 "    BL      sub_FFAA23CC_my \n"  // --> Patched. Old value = 0xFFAA23CC. Close stage
 194 "    B       loc_FFAA2560 \n"
 195 );
 196 }
 197 
 198 /*************************************************************/
 199 //** sub_FFAA2234_my @ 0xFFAA2234 - 0xFFAA23C8, length=102
 200 void __attribute__((naked,noinline)) sub_FFAA2234_my() {
 201 asm volatile (
 202 "    STMFD   SP!, {R4-R9,LR} \n"
 203 "    MOV     R4, R0 \n"
 204 
 205 //hook placed here to avoid conditional branch a few instructions below (watch out for registers!)
 206 "    MOV   R0, R4\n"      //data block start, commented out as R0 is already holding what we need
 207 "    BL filewrite_main_hook\n"
 208 "    MOV     R0, R4\n"      //restore register(s)
 209 //hook end
 210 
 211 "    LDR     R0, [R0, #0x4C] \n"
 212 "    SUB     SP, SP, #0x3C \n"
 213 "    TST     R0, #1 \n"
 214 "    BEQ     loc_FFAA239C \n"
 215 "    LDR     R7, =0xB460 \n"
 216 "    LDR     R0, [R7, #0x18] \n"
 217 "    CMP     R0, #0 \n"
 218 "    BLXNE   R0 \n"
 219 "    ADD     R0, R4, #0x58 \n"
 220 "    BL      sub_FF830358 \n"
 221 "    MOV     R1, #0 \n"
 222 "    BL      sub_FF82E08C \n"
 223 "    LDR     R0, [R4, #0xC] \n"
 224 "    BL      sub_FF82D128 \n"
 225 "    LDR     R0, [R4, #0x4C] \n"
 226 "    LDR     R5, =0x301 \n"
 227 "    TST     R0, #0x10 \n"
 228 "    MOVNE   R5, #9 \n"
 229 "    BNE     loc_FFAA2290 \n"
 230 "    TST     R0, #0x40 \n"
 231 "    MOVNE   R5, #1 \n"
 232 
 233 "loc_FFAA2290:\n"
 234 "    TST     R0, #0x20 \n"
 235 "    BNE     loc_FFAA22A4 \n"
 236 "    LDR     R0, [R4, #0x54] \n"
 237 "    CMP     R0, #1 \n"
 238 "    BNE     loc_FFAA22A8 \n"
 239 
 240 "loc_FFAA22A4:\n"
 241 "    ORR     R5, R5, #0x8000 \n"
 242 
 243 "loc_FFAA22A8:\n"
 244 "    LDR     R9, =0x1B6 \n"
 245 "    ADD     R8, R4, #0x58 \n"
 246 "    LDR     R6, [R4, #0xC] \n"
 247 "    MOV     R2, R9 \n"
 248 "    MOV     R1, R5 \n"
 249 "    MOV     R0, R8 \n"
 250 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 251 "    CMN     R0, #1 \n"
 252 "    BNE     loc_FFAA2328 \n"
 253 "    MOV     R0, R8 \n"
 254 "    BL      sub_FF8277FC \n"
 255 "    MOV     R2, #0xF \n"
 256 "    MOV     R1, R8 \n"
 257 "    ADD     R0, SP, #4 \n"
 258 "    BL      sub_006BCD9C \n"
 259 "    MOV     R0, #0 \n"
 260 "    LDR     R1, =0x41FF \n"
 261 "    STRB    R0, [SP, #0x13] \n"
 262 "    STR     R1, [SP, #0x24] \n"
 263 "    MOV     R1, #0x10 \n"
 264 "    STR     R0, [SP, #0x2C] \n"
 265 "    STR     R1, [SP, #0x28] \n"
 266 "    ADD     R1, SP, #0x24 \n"
 267 "    ADD     R0, SP, #4 \n"
 268 "    STR     R6, [SP, #0x30] \n"
 269 "    STR     R6, [SP, #0x34] \n"
 270 "    STR     R6, [SP, #0x38] \n"
 271 "    BL      sub_FF82D9F0 \n"
 272 "    MOV     R2, R9 \n"
 273 "    MOV     R1, R5 \n"
 274 "    MOV     R0, R8 \n"
 275 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 276 
 277 "loc_FFAA2328:\n"
 278 "    CMN     R0, #1 \n"
 279 "    MOV     R5, R0 \n"
 280 "    STR     R0, [R7, #4] \n"
 281 "    BNE     loc_FFAA2364 \n"
 282 "    ADD     R0, R4, #0x58 \n"
 283 "    BL      sub_FF830358 \n"
 284 "    LDR     R1, [R7, #0x1C] \n"
 285 "    BL      sub_FF82E1CC \n"
 286 "    LDR     R1, [R7, #0x14] \n"
 287 "    CMP     R1, #0 \n"
 288 "    BEQ     loc_FFAA23C4 \n"
 289 "    ADD     SP, SP, #0x3C \n"
 290 "    LDMFD   SP!, {R4-R9,LR} \n"
 291 "    LDR     R0, =0x9200001 \n"
 292 "    BX      R1 \n"
 293 
 294 "loc_FFAA2364:\n"
 295 "    LDR     R0, =0xFC318 \n"
 296 "    MOV     R2, #0x20 \n"
 297 "    ADD     R1, R4, #0x58 \n"
 298 "    BL      sub_006BCF84 \n"
 299 
 300 //mod start
 301 "    LDR R3, =current_write_ignored\n"
 302 "    LDR R3, [R3]\n"
 303 "    CMP R3, #0\n"
 304 "    BNE loc_C\n" // jump over the next block
 305 //mod end
 306 
 307 "    LDR     R0, [R4, #0x4C] \n"
 308 "    TST     R0, #0x80 \n"
 309 "    BEQ     loc_FFAA239C \n"
 310 "    LDR     R1, [R4, #8] \n"
 311 "    MOV     R0, R5 \n"
 312 "    BL      sub_FF8274CC \n"
 313 "    CMP     R0, #0 \n"
 314 "    MOVEQ   R1, R4 \n"
 315 "    MOVEQ   R0, #7 \n"
 316 "    BEQ     loc_FFAA23C0 \n"
 317 
 318 "loc_FFAA239C:\n"
 319 "loc_C:\n"
 320 "    LDR     R0, [R4, #0x4C] \n"
 321 "    TST     R0, #0x40 \n"
 322 "    LDREQ   R0, [R4, #4] \n"
 323 "    CMPEQ   R0, #0 \n"
 324 "    MOVNE   R1, R4 \n"
 325 "    MOVNE   R0, #9 \n"
 326 "    BLNE    sub_FFAA2174 \n"
 327 "    MOV     R1, R4 \n"
 328 "    MOV     R0, #0 \n"
 329 
 330 "loc_FFAA23C0:\n"
 331 "    BL      sub_FFAA2174 \n"
 332 
 333 "loc_FFAA23C4:\n"
 334 "    ADD     SP, SP, #0x3C \n"
 335 "    LDMFD   SP!, {R4-R9,PC} \n"
 336 );
 337 }
 338 
 339 /*************************************************************/
 340 //** sub_FFAA2914_my @ 0xFFAA2914 - 0xFFAA29F8, length=58
 341 void __attribute__((naked,noinline)) sub_FFAA2914_my() {
 342 asm volatile (
 343 "    STMFD   SP!, {R4-R10,LR} \n"
 344 "    MOV     R5, R0 \n"
 345 "    LDR     R0, [R0] \n"
 346 "    CMP     R0, #6 \n"
 347 "    BHI     loc_FFAA2940 \n"
 348 "    ADD     R0, R5, R0, LSL#3 \n"
 349 "    LDR     R8, [R0, #0x14]! \n"
 350 "    LDR     R7, [R0, #4] \n"
 351 "    CMP     R7, #0 \n"
 352 "    BNE     loc_FFAA295C \n"
 353 "    B       loc_FFAA2950 \n"
 354 
 355 "loc_FFAA2940:\n"
 356 "    LDR     R2, =0x34A \n"
 357 "    LDR     R1, =0xFFAA2720 /*'dwFWrite.c'*/ \n"
 358 "    MOV     R0, #0 \n"
 359 "    BL      _DebugAssert \n"
 360 
 361 "loc_FFAA2950:\n"
 362 "    MOV     R1, R5 \n"
 363 "    MOV     R0, #7 \n"
 364 "    B       loc_FFAA29F4 \n"
 365 
 366 "loc_FFAA295C:\n"
 367 "    LDR     R9, =0xB460 \n"
 368 "    MOV     R4, R7 \n"
 369 
 370 "loc_FFAA2964:\n"
 371 "    LDR     R0, [R5, #4] \n"
 372 "    CMP     R4, #0x1000000 \n"
 373 "    MOVLS   R6, R4 \n"
 374 "    MOVHI   R6, #0x1000000 \n"
 375 "    BIC     R1, R0, #0xFF000000 \n"
 376 "    CMP     R1, #0 \n"
 377 "    BICNE   R0, R0, #0xFF000000 \n"
 378 "    RSBNE   R0, R0, #0x1000000 \n"
 379 "    CMPNE   R6, R0 \n"
 380 "    MOVHI   R6, R0 \n"
 381 "    LDR     R0, [R9, #4] \n"
 382 "    MOV     R2, R6 \n"
 383 "    MOV     R1, R8 \n"
 384 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 385 "    LDR     R1, [R5, #4] \n"
 386 "    CMP     R6, R0 \n"
 387 "    ADD     R1, R1, R0 \n"
 388 "    STR     R1, [R5, #4] \n"
 389 "    BEQ     loc_FFAA29C4 \n"
 390 "    CMN     R0, #1 \n"
 391 "    LDRNE   R0, =0x9200015 \n"
 392 "    LDREQ   R0, =0x9200005 \n"
 393 "    STR     R0, [R5, #0x10] \n"
 394 "    B       loc_FFAA2950 \n"
 395 
 396 "loc_FFAA29C4:\n"
 397 "    SUB     R4, R4, R0 \n"
 398 "    CMP     R4, R7 \n"
 399 "    LDRCS   R2, =0x375 \n"
 400 "    ADD     R8, R8, R0 \n"
 401 "    LDRCS   R1, =0xFFAA2720 /*'dwFWrite.c'*/ \n"
 402 "    MOVCS   R0, #0 \n"
 403 "    BLCS    _DebugAssert \n"
 404 "    CMP     R4, #0 \n"
 405 "    BNE     loc_FFAA2964 \n"
 406 "    LDR     R0, [R5] \n"
 407 "    MOV     R1, R5 \n"
 408 "    ADD     R0, R0, #1 \n"
 409 
 410 "loc_FFAA29F4:\n"
 411 "    LDMFD   SP!, {R4-R10,LR} \n"
 412 "    B       sub_FFAA2174 \n"
 413 "    .ltorg\n" //+
 414 );
 415 }
 416 
 417 /*************************************************************/
 418 //** sub_FFAA23CC_my @ 0xFFAA23CC - 0xFFAA240C, length=17
 419 void __attribute__((naked,noinline)) sub_FFAA23CC_my() {
 420 asm volatile (
 421 "    STMFD   SP!, {R4-R6,LR} \n"
 422 "    MOV     R4, R0 \n"
 423 "    LDR     R0, [R0, #0x4C] \n"
 424 "    LDR     R5, =0xB460 \n"
 425 "    TST     R0, #2 \n"
 426 "    SUB     SP, SP, #0x38 \n"
 427 "    BEQ     sub_FFAA2534 \n"
 428 "    LDR     R0, [R5, #4] \n"
 429 "    CMN     R0, #1 \n"
 430 "    BEQ     sub_FFAA2420 \n"
 431 "    LDR     R1, [R4, #0x54] \n"
 432 "    LDR     R6, =0x9200003 \n"
 433 "    CMP     R1, #1 \n"
 434 "    BNE     loc_FFAA240C \n"
 435 //mod start
 436 "    LDR R3, =current_write_ignored\n"
 437 "    LDR R3, [R3]\n"
 438 "    CMP R3, #0\n"
 439 "    BNE loc_D\n" // jump over the next block
 440 //mod end
 441 
 442 "    BL      sub_FF827220 \n"
 443 "    B       sub_FFAA2410 \n"
 444 
 445 "loc_FFAA240C:\n"
 446 "loc_D:\n"
 447 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 448 "    LDR     PC, =0xFFAA2410 \n"  // Continue in firmware
 449 );
 450 }

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