root/platform/ixus170_elph170/sub/100a/filewrite.c

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFAB1AB0_my
  3. sub_FFAB220C_my
  4. sub_FFAB1C68_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                               // Found in sub_FFABBB58 (1.00a) --> "CMP     R0, #6" and
  14                               // filewritetask() jump table has 7 calls to loc_FFABB944
  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_FWT];
  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 @ 0xFFAB1DFC - 0xFFAB1FC4, length=115
  46 void __attribute__((naked,noinline)) filewritetask() {
  47 asm volatile (
  48 "    STMFD   SP!, {R1-R7,LR} \n"
  49 "    LDR     R5, =0xB7EC \n"
  50 "    MOV     R6, #0 \n"
  51 
  52 "loc_FFAB1E08:\n"
  53 "    LDR     R0, [R5, #0x10] \n"
  54 "    MOV     R2, #0 \n"
  55 "    ADD     R1, SP, #8 \n"
  56 "    BL      sub_FF829E30 /*_ReceiveMessageQueue*/ \n"
  57 "    CMP     R0, #0 \n"
  58 "    LDRNE   R2, =0x409 \n"
  59 "    LDRNE   R1, =0xFFAB1FF0 /*'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_FFAB1E08 \n"
  67 "    B       loc_FFAB1FB8 \n"
  68 "    B       loc_FFAB1FB8 \n"
  69 "    B       loc_FFAB1FB8 \n"
  70 "    B       loc_FFAB1FB8 \n"
  71 "    B       loc_FFAB1FB8 \n"
  72 "    B       loc_FFAB1FB8 \n"
  73 "    B       loc_FFAB1FB8 \n"
  74 "    B       loc_FFAB1FC0 \n"
  75 "    B       loc_FFAB1E74 \n"
  76 "    B       loc_FFAB1F34 \n"
  77 "    B       loc_FFAB1F64 \n"
  78 "    B       loc_FFAB1EE8 \n"
  79 "    B       loc_FFAB1F2C \n"
  80 
  81 "loc_FFAB1E74:\n"
  82 "    MOV     R4, R5 \n"
  83 "    STR     R6, [SP] \n"
  84 
  85 "loc_FFAB1E7C:\n"
  86 "    LDR     R0, [R4, #0x10] \n"
  87 "    MOV     R1, SP \n"
  88 "    BL      sub_FF82A0AC /*_GetNumberOfPostedMessages*/ \n"
  89 "    LDR     R0, [SP] \n"
  90 "    CMP     R0, #0 \n"
  91 "    BEQ     loc_FFAB1EA8 \n"
  92 "    LDR     R0, [R4, #0x10] \n"
  93 "    MOV     R2, #0 \n"
  94 "    ADD     R1, SP, #4 \n"
  95 "    BL      sub_FF829E30 /*_ReceiveMessageQueue*/ \n"
  96 "    B       loc_FFAB1E7C \n"
  97 
  98 "loc_FFAB1EA8:\n"
  99 "    LDR     R0, [R4, #4] \n"
 100 "    CMN     R0, #1 \n"
 101 "    BEQ     loc_FFAB1EDC \n"
 102 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 103 "    MVN     R0, #0 \n"
 104 "    STR     R0, [R4, #4] \n"
 105 "    MOV     R1, #0 \n"
 106 "    MOV     R0, #0x48 \n"
 107 "    BL      sub_FF8B38E0 \n"
 108 "    LDR     R0, =0x1087C0 \n"
 109 "    BL      sub_FF83222C \n"
 110 "    MOV     R1, #0 \n"
 111 "    BL      sub_FF8300F8 \n"
 112 
 113 "loc_FFAB1EDC:\n"
 114 "    LDR     R0, [R4, #0xC] \n"
 115 "    BL      _GiveSemaphore \n"
 116 "    B       loc_FFAB1E08 \n"
 117 
 118 "loc_FFAB1EE8:\n"
 119 "    MOV     R4, R0 \n"
 120 "    ADD     R0, R0, #0x58 \n"
 121 "    BL      sub_FF83222C \n"
 122 "    MOV     R1, #0 \n"
 123 "    BL      sub_FF82FFB8 \n"
 124 "    MOV     R1, #0 \n"
 125 "    MOV     R0, #0x47 \n"
 126 "    BL      sub_FF8B38E0 \n"
 127 "    LDR     R0, [R4, #0xC] \n"
 128 "    BL      sub_FF82F038 \n"
 129 "    ADD     R0, R4, #0x58 \n"
 130 
 131 //mod start
 132 "    LDR R3, =ignore_current_write\n" // !!
 133 "    LDR R3, [R3]\n"
 134 "    CMP R3, #0\n"
 135 "    BNE loc_A\n" // skip creating directory
 136 //mod end
 137 
 138 "    BL      sub_FF8281A4 \n"
 139 "    MOV     R1, #0 \n"
 140 "    MOV     R0, #0x48 \n"
 141 "    BL      sub_FF8B38E0 \n"
 142 "    ADD     R0, R4, #0x58 \n"
 143 "    B       loc_FFAB1F98 \n"
 144 
 145 "loc_FFAB1F2C:\n"
 146 "    BL      sub_FFAB1AB0_my \n"  // --> Patched. Old value = 0xFFAB1AB0. Open stage
 147 "    B       loc_FFAB1E08 \n"
 148 
 149 "loc_FFAB1F34:\n"
 150 "    LDR     R1, [R0, #4] \n"
 151 "    MOV     R4, R0 \n"
 152 "    LDR     R0, [R5, #4] \n"
 153 "    MOV     R2, #0 \n"
 154 "    BL      fwt_lseek \n"  // --> Patched. Old value = _lseek.
 155 "    CMN     R0, #1 \n"
 156 "    LDREQ   R0, =0x9200013 \n"
 157 "    MOVEQ   R1, R4 \n"
 158 "    STREQ   R0, [R4, #0x10] \n"
 159 "    MOVEQ   R0, #7 \n"
 160 "    BLEQ    sub_FFAB19F0 \n"
 161 "    B       loc_FFAB1E08 \n"
 162 
 163 "loc_FFAB1F64:\n"
 164 "    MOV     R4, R0 \n"
 165 "    LDRSB   R0, [R0, #0x58] \n"
 166 "    CMP     R0, #0 \n"
 167 "    BEQ     loc_FFAB1E08 \n"
 168 "    STRB    R0, [SP, #4] \n"
 169 "    ADD     R0, R4, #0x58 \n"
 170 "    STRB    R6, [SP, #5] \n"
 171 "    BL      sub_FF83222C \n"
 172 "    MOV     R1, #0 \n"
 173 "    BL      sub_FF82FFB8 \n"
 174 
 175 //mod start
 176 "    LDR R3, =ignore_current_write\n" // !!
 177 "    LDR R3, [R3]\n"
 178 "    CMP R3, #0\n"
 179 "    BNE loc_B\n" // skip flushing the cache
 180 //mod end
 181 
 182 "    ADD     R0, SP, #4 \n"
 183 "    BL      sub_FF82F050 \n"
 184 "loc_B:\n"
 185 "    ADD     R0, R4, #0x58 \n"
 186 
 187 "loc_FFAB1F98:\n"
 188 "loc_A:\n"
 189 "    BL      sub_FF83222C \n"
 190 "    LDR     R1, [R5, #0x1C] \n"
 191 "    BL      sub_FF8300F8 \n"
 192 "    LDR     R1, [R5, #0x14] \n"
 193 "    CMP     R1, #0 \n"
 194 "    LDRNE   R0, [R4, #0x10] \n"
 195 "    BLXNE   R1 \n"
 196 "    B       loc_FFAB1E08 \n"
 197 
 198 "loc_FFAB1FB8:\n"
 199 "    BL      sub_FFAB220C_my \n"  // --> Patched. Old value = 0xFFAB220C. Write stage
 200 "    B       loc_FFAB1E08 \n"
 201 
 202 "loc_FFAB1FC0:\n"
 203 "    BL      sub_FFAB1C68_my \n"  // --> Patched. Old value = 0xFFAB1C68. Close stage
 204 "    B       loc_FFAB1E08 \n"
 205 );
 206 }
 207 
 208 /*************************************************************/
 209 //** sub_FFAB1AB0_my @ 0xFFAB1AB0 - 0xFFAB1C64, length=110
 210 void __attribute__((naked,noinline)) sub_FFAB1AB0_my() {
 211 asm volatile (
 212 "    STMFD   SP!, {R4-R9,LR} \n"
 213 "    MOV     R4, R0 \n"
 214 
 215 //hook placed here to avoid conditional branch a few instructions below (watch out for registers!)
 216 "    MOV   R0, R4\n"      //data block start, commented out as R0 is already holding what we need
 217 "    BL filewrite_main_hook\n"
 218 "    MOV     R0, R4\n"      //restore register(s)
 219 //hook end
 220 
 221 "    LDR     R0, [R0, #0x4C] \n"
 222 "    SUB     SP, SP, #0x3C \n"
 223 "    TST     R0, #1 \n"
 224 "    BEQ     loc_FFAB1C38 \n"
 225 "    LDR     R7, =0xB7EC \n"
 226 "    LDR     R0, [R7, #0x18] \n"
 227 "    CMP     R0, #0 \n"
 228 "    BLXNE   R0 \n"
 229 "    ADD     R0, R4, #0x58 \n"
 230 "    BL      sub_FF83222C \n"
 231 "    MOV     R1, #0 \n"
 232 "    BL      sub_FF82FFB8 \n"
 233 "    MOV     R1, #0 \n"
 234 "    MOV     R0, #0x47 \n"
 235 "    BL      sub_FF8B38E0 \n"
 236 "    LDR     R0, [R4, #0xC] \n"
 237 "    BL      sub_FF82F038 \n"
 238 "    LDR     R0, [R4, #0x4C] \n"
 239 "    LDR     R5, =0x301 \n"
 240 "    TST     R0, #0x10 \n"
 241 "    MOVNE   R5, #9 \n"
 242 "    BNE     loc_FFAB1B18 \n"
 243 "    TST     R0, #0x40 \n"
 244 "    MOVNE   R5, #1 \n"
 245 
 246 "loc_FFAB1B18:\n"
 247 "    TST     R0, #0x20 \n"
 248 "    BNE     loc_FFAB1B2C \n"
 249 "    LDR     R0, [R4, #0x54] \n"
 250 "    CMP     R0, #1 \n"
 251 "    BNE     loc_FFAB1B30 \n"
 252 
 253 "loc_FFAB1B2C:\n"
 254 "    ORR     R5, R5, #0x8000 \n"
 255 
 256 "loc_FFAB1B30:\n"
 257 "    LDR     R9, =0x1B6 \n"
 258 "    ADD     R8, R4, #0x58 \n"
 259 "    LDR     R6, [R4, #0xC] \n"
 260 "    MOV     R2, R9 \n"
 261 "    MOV     R1, R5 \n"
 262 "    MOV     R0, R8 \n"
 263 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 264 "    CMN     R0, #1 \n"
 265 "    BNE     loc_FFAB1BB0 \n"
 266 "    MOV     R0, R8 \n"
 267 "    BL      sub_FF8281A4 \n"
 268 "    MOV     R2, #0xF \n"
 269 "    MOV     R1, R8 \n"
 270 "    ADD     R0, SP, #4 \n"
 271 "    BL      sub_006BA828 \n"
 272 "    MOV     R0, #0 \n"
 273 "    LDR     R1, =0x41FF \n"
 274 "    STRB    R0, [SP, #0x13] \n"
 275 "    STR     R1, [SP, #0x24] \n"
 276 "    MOV     R1, #0x10 \n"
 277 "    STR     R0, [SP, #0x2C] \n"
 278 "    STR     R1, [SP, #0x28] \n"
 279 "    ADD     R1, SP, #0x24 \n"
 280 "    ADD     R0, SP, #4 \n"
 281 "    STR     R6, [SP, #0x30] \n"
 282 "    STR     R6, [SP, #0x34] \n"
 283 "    STR     R6, [SP, #0x38] \n"
 284 "    BL      sub_FF82F91C \n"
 285 "    MOV     R2, R9 \n"
 286 "    MOV     R1, R5 \n"
 287 "    MOV     R0, R8 \n"
 288 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 289 
 290 "loc_FFAB1BB0:\n"
 291 "    CMN     R0, #1 \n"
 292 "    MOV     R5, R0 \n"
 293 "    STR     R0, [R7, #4] \n"
 294 "    BNE     loc_FFAB1BF8 \n"
 295 "    MOV     R1, #0 \n"
 296 "    MOV     R0, #0x48 \n"
 297 "    BL      sub_FF8B38E0 \n"
 298 "    ADD     R0, R4, #0x58 \n"
 299 "    BL      sub_FF83222C \n"
 300 "    LDR     R1, [R7, #0x1C] \n"
 301 "    BL      sub_FF8300F8 \n"
 302 "    LDR     R1, [R7, #0x14] \n"
 303 "    CMP     R1, #0 \n"
 304 "    BEQ     loc_FFAB1C60 \n"
 305 "    ADD     SP, SP, #0x3C \n"
 306 "    LDMFD   SP!, {R4-R9,LR} \n"
 307 "    LDR     R0, =0x9200001 \n"
 308 "    BX      R1 \n"
 309 
 310 "loc_FFAB1BF8:\n"
 311 "    LDR     R0, =0x1087C0 \n"
 312 "    MOV     R2, #0x20 \n"
 313 "    ADD     R1, R4, #0x58 \n"
 314 "    BL      sub_006BAA10 \n"
 315 
 316 //mod start
 317 "    LDR R3, =current_write_ignored\n"
 318 "    LDR R3, [R3]\n"
 319 "    CMP R3, #0\n"
 320 "    BNE loc_C\n" // jump over the next block
 321 //mod end
 322 
 323 "    LDR     R0, [R4, #0x4C] \n"
 324 "    TST     R0, #0x80 \n"
 325 "    BEQ     loc_FFAB1C38 \n"
 326 "    LDR     R1, [R4, #8] \n"
 327 "    MOV     R0, R5 \n"
 328 "    BL      sub_FF827E74 \n"
 329 "    CMP     R0, #0 \n"
 330 "    LDREQ   R0, =0x9200017 \n"
 331 "    MOVEQ   R1, R4 \n"
 332 "    STREQ   R0, [R4, #0x10] \n"
 333 "    MOVEQ   R0, #7 \n"
 334 "    BEQ     loc_FFAB1C5C \n"
 335 
 336 "loc_FFAB1C38:\n"
 337 "loc_C:\n"
 338 "    LDR     R0, [R4, #0x4C] \n"
 339 "    TST     R0, #0x40 \n"
 340 "    LDREQ   R0, [R4, #4] \n"
 341 "    CMPEQ   R0, #0 \n"
 342 "    MOVNE   R1, R4 \n"
 343 "    MOVNE   R0, #9 \n"
 344 "    BLNE    sub_FFAB19F0 \n"
 345 "    MOV     R1, R4 \n"
 346 "    MOV     R0, #0 \n"
 347 
 348 "loc_FFAB1C5C:\n"
 349 "    BL      sub_FFAB19F0 \n"
 350 
 351 "loc_FFAB1C60:\n"
 352 "    ADD     SP, SP, #0x3C \n"
 353 "    LDMFD   SP!, {R4-R9,PC} \n"
 354 );
 355 }
 356 
 357 /*************************************************************/
 358 //** sub_FFAB220C_my @ 0xFFAB220C - 0xFFAB22F0, length=58
 359 void __attribute__((naked,noinline)) sub_FFAB220C_my() {
 360 asm volatile (
 361 "    STMFD   SP!, {R4-R10,LR} \n"
 362 "    MOV     R5, R0 \n"
 363 "    LDR     R0, [R0] \n"
 364 "    CMP     R0, #6 \n"
 365 "    BHI     loc_FFAB2238 \n"
 366 "    ADD     R0, R5, R0, LSL#3 \n"
 367 "    LDR     R8, [R0, #0x14]! \n"
 368 "    LDR     R7, [R0, #4] \n"
 369 "    CMP     R7, #0 \n"
 370 "    BNE     loc_FFAB2254 \n"
 371 "    B       loc_FFAB2248 \n"
 372 
 373 "loc_FFAB2238:\n"
 374 "    LDR     R2, =0x35E \n"
 375 "    LDR     R1, =0xFFAB1FF0 /*'dwFWrite.c'*/ \n"
 376 "    MOV     R0, #0 \n"
 377 "    BL      _DebugAssert \n"
 378 
 379 "loc_FFAB2248:\n"
 380 "    MOV     R1, R5 \n"
 381 "    MOV     R0, #7 \n"
 382 "    B       loc_FFAB22EC \n"
 383 
 384 "loc_FFAB2254:\n"
 385 "    LDR     R9, =0xB7EC \n"
 386 "    MOV     R4, R7 \n"
 387 
 388 "loc_FFAB225C:\n"
 389 "    LDR     R0, [R5, #4] \n"
 390 "    CMP     R4, #0x1000000 \n"
 391 "    MOVLS   R6, R4 \n"
 392 "    MOVHI   R6, #0x1000000 \n"
 393 "    BIC     R1, R0, #0xFF000000 \n"
 394 "    CMP     R1, #0 \n"
 395 "    BICNE   R0, R0, #0xFF000000 \n"
 396 "    RSBNE   R0, R0, #0x1000000 \n"
 397 "    CMPNE   R6, R0 \n"
 398 "    MOVHI   R6, R0 \n"
 399 "    LDR     R0, [R9, #4] \n"
 400 "    MOV     R2, R6 \n"
 401 "    MOV     R1, R8 \n"
 402 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 403 "    LDR     R1, [R5, #4] \n"
 404 "    CMP     R6, R0 \n"
 405 "    ADD     R1, R1, R0 \n"
 406 "    STR     R1, [R5, #4] \n"
 407 "    BEQ     loc_FFAB22BC \n"
 408 "    CMN     R0, #1 \n"
 409 "    LDRNE   R0, =0x9200015 \n"
 410 "    LDREQ   R0, =0x9200005 \n"
 411 "    STR     R0, [R5, #0x10] \n"
 412 "    B       loc_FFAB2248 \n"
 413 
 414 "loc_FFAB22BC:\n"
 415 "    SUB     R4, R4, R0 \n"
 416 "    CMP     R4, R7 \n"
 417 "    LDRCS   R2, =0x389 \n"
 418 "    ADD     R8, R8, R0 \n"
 419 "    LDRCS   R1, =0xFFAB1FF0 /*'dwFWrite.c'*/ \n"
 420 "    MOVCS   R0, #0 \n"
 421 "    BLCS    _DebugAssert \n"
 422 "    CMP     R4, #0 \n"
 423 "    BNE     loc_FFAB225C \n"
 424 "    LDR     R0, [R5] \n"
 425 "    MOV     R1, R5 \n"
 426 "    ADD     R0, R0, #1 \n"
 427 
 428 "loc_FFAB22EC:\n"
 429 "    LDMFD   SP!, {R4-R10,LR} \n"
 430 "    B       sub_FFAB19F0 \n"
 431 "    .ltorg\n" //+
 432 );
 433 }
 434 
 435 /*************************************************************/
 436 //** sub_FFAB1C68_my @ 0xFFAB1C68 - 0xFFAB1CA8, length=17
 437 void __attribute__((naked,noinline)) sub_FFAB1C68_my() {
 438 asm volatile (
 439 "    STMFD   SP!, {R4-R6,LR} \n"
 440 "    MOV     R4, R0 \n"
 441 "    LDR     R0, [R0, #0x4C] \n"
 442 "    LDR     R5, =0xB7EC \n"
 443 "    TST     R0, #2 \n"
 444 "    SUB     SP, SP, #0x38 \n"
 445 "    BEQ     sub_FFAB1DDC \n"
 446 "    LDR     R0, [R5, #4] \n"
 447 "    CMN     R0, #1 \n"
 448 "    BEQ     sub_FFAB1CBC \n"
 449 "    LDR     R1, [R4, #0x54] \n"
 450 "    LDR     R6, =0x9200003 \n"
 451 "    CMP     R1, #1 \n"
 452 "    BNE     loc_FFAB1CA8 \n"
 453 //mod start
 454 "    LDR R3, =current_write_ignored\n"
 455 "    LDR R3, [R3]\n"
 456 "    CMP R3, #0\n"
 457 "    BNE loc_D\n" // jump over the next block
 458 //mod end
 459 
 460 "    BL      sub_FF827BC8 \n"
 461 "    B       sub_FFAB1CAC \n"
 462 
 463 "loc_FFAB1CA8:\n"
 464 "loc_D:\n"
 465 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 466 "    LDR     PC, =0xFFAB1CAC \n"  // Continue in firmware
 467 );
 468 }

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