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

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFAB5800_my
  3. sub_FFAB5EE0_my
  4. sub_FFAB5998_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 //** filewritetask @ 0xFFAB5B20 - 0xFFAB5CC4, length=106
  45 void __attribute__((naked,noinline)) filewritetask() {
  46 asm volatile (
  47 "    STMFD   SP!, {R1-R7,LR} \n"
  48 "    LDR     R5, =0xBA84 \n"
  49 "    MOV     R6, #0 \n"
  50 
  51 "loc_FFAB5B2C:\n"
  52 "    LDR     R0, [R5, #0x10] \n"
  53 "    MOV     R2, #0 \n"
  54 "    ADD     R1, SP, #8 \n"
  55 "    BL      sub_003F84B8 /*_ReceiveMessageQueue*/ \n"
  56 "    CMP     R0, #0 \n"
  57 "    LDRNE   R2, =0x3F5 \n"
  58 "    LDRNE   R1, =0xFFAB5CEC /*'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_FFAB5B2C \n"
  66 "    B       loc_FFAB5CB8 \n"
  67 "    B       loc_FFAB5CB8 \n"
  68 "    B       loc_FFAB5CB8 \n"
  69 "    B       loc_FFAB5CB8 \n"
  70 "    B       loc_FFAB5CB8 \n"
  71 "    B       loc_FFAB5CB8 \n"
  72 "    B       loc_FFAB5CB8 \n"
  73 "    B       loc_FFAB5CC0 \n"
  74 "    B       loc_FFAB5B98 \n"
  75 "    B       loc_FFAB5C34 \n"
  76 "    B       loc_FFAB5C64 \n"
  77 "    B       loc_FFAB5C00 \n"
  78 "    B       loc_FFAB5C2C \n"
  79 
  80 "loc_FFAB5B98:\n"
  81 "    MOV     R4, R5 \n"
  82 "    STR     R6, [SP] \n"
  83 
  84 "loc_FFAB5BA0:\n"
  85 "    LDR     R0, [R4, #0x10] \n"
  86 "    MOV     R1, SP \n"
  87 "    BL      sub_003F8710 /*_GetNumberOfPostedMessages*/ \n"
  88 "    LDR     R0, [SP] \n"
  89 "    CMP     R0, #0 \n"
  90 "    BEQ     loc_FFAB5BCC \n"
  91 "    LDR     R0, [R4, #0x10] \n"
  92 "    MOV     R2, #0 \n"
  93 "    ADD     R1, SP, #4 \n"
  94 "    BL      sub_003F84B8 /*_ReceiveMessageQueue*/ \n"
  95 "    B       loc_FFAB5BA0 \n"
  96 
  97 "loc_FFAB5BCC:\n"
  98 "    LDR     R0, [R4, #4] \n"
  99 "    CMN     R0, #1 \n"
 100 "    BEQ     loc_FFAB5BF4 \n"
 101 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 102 "    MVN     R0, #0 \n"
 103 "    STR     R0, [R4, #4] \n"
 104 "    LDR     R0, =0xF1EA8 \n"
 105 "    BL      sub_FF820584 \n"
 106 "    MOV     R1, #0 \n"
 107 "    BL      sub_FF81E400 \n"
 108 
 109 "loc_FFAB5BF4:\n"
 110 "    LDR     R0, [R4, #0xC] \n"
 111 "    BL      _GiveSemaphore \n"
 112 "    B       loc_FFAB5B2C \n"
 113 
 114 "loc_FFAB5C00:\n"
 115 "    MOV     R4, R0 \n"
 116 "    ADD     R0, R0, #0x58 \n"
 117 "    BL      sub_FF820584 \n"
 118 "    MOV     R1, #0 \n"
 119 "    BL      sub_FF81E2C0 \n"
 120 "    LDR     R0, [R4, #0xC] \n"
 121 "    BL      sub_FF81D180 \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_FF8178D0 \n"
 131 "    ADD     R0, R4, #0x58 \n"
 132 "    B       loc_FFAB5C98 \n"
 133 
 134 "loc_FFAB5C2C:\n"
 135 "    BL      sub_FFAB5800_my \n"  // --> Patched. Old value = 0xFFAB5800. Open stage
 136 "    B       loc_FFAB5B2C \n"
 137 
 138 "loc_FFAB5C34:\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_FFAB5740 \n"
 150 "    B       loc_FFAB5B2C \n"
 151 
 152 "loc_FFAB5C64:\n"
 153 "    MOV     R4, R0 \n"
 154 "    LDRSB   R0, [R0, #0x58] \n"
 155 "    CMP     R0, #0 \n"
 156 "    BEQ     loc_FFAB5B2C \n"
 157 "    STRB    R0, [SP, #4] \n"
 158 "    ADD     R0, R4, #0x58 \n"
 159 "    STRB    R6, [SP, #5] \n"
 160 "    BL      sub_FF820584 \n"
 161 "    MOV     R1, #0 \n"
 162 "    BL      sub_FF81E2C0 \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_FF81D198 \n"
 173 "loc_B:\n"
 174 "    ADD     R0, R4, #0x58 \n"
 175 
 176 "loc_FFAB5C98:\n"
 177 "loc_A:\n"
 178 "    BL      sub_FF820584 \n"
 179 "    LDR     R1, [R5, #0x1C] \n"
 180 "    BL      sub_FF81E400 \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_FFAB5B2C \n"
 186 
 187 "loc_FFAB5CB8:\n"
 188 "    BL      sub_FFAB5EE0_my \n"  // --> Patched. Old value = 0xFFAB5EE0. Write stage
 189 "    B       loc_FFAB5B2C \n"
 190 
 191 "loc_FFAB5CC0:\n"
 192 "    BL      sub_FFAB5998_my \n"  // --> Patched. Old value = 0xFFAB5998. Close stage
 193 "    B       loc_FFAB5B2C \n"
 194 );
 195 }
 196 
 197 /*************************************************************/
 198 //** sub_FFAB5800_my @ 0xFFAB5800 - 0xFFAB5994, length=102
 199 void __attribute__((naked,noinline)) sub_FFAB5800_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_FFAB5968 \n"
 212 "    LDR     R7, =0xBA84 \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_FF820584 \n"
 218 "    MOV     R1, #0 \n"
 219 "    BL      sub_FF81E2C0 \n"
 220 "    LDR     R0, [R4, #0xC] \n"
 221 "    BL      sub_FF81D180 \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_FFAB585C \n"
 227 "    TST     R0, #0x40 \n"
 228 "    MOVNE   R5, #1 \n"
 229 
 230 "loc_FFAB585C:\n"
 231 "    TST     R0, #0x20 \n"
 232 "    BNE     loc_FFAB5870 \n"
 233 "    LDR     R0, [R4, #0x54] \n"
 234 "    CMP     R0, #1 \n"
 235 "    BNE     loc_FFAB5874 \n"
 236 
 237 "loc_FFAB5870:\n"
 238 "    ORR     R5, R5, #0x8000 \n"
 239 
 240 "loc_FFAB5874:\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_FFAB58F4 \n"
 250 "    MOV     R0, R8 \n"
 251 "    BL      sub_FF8178D0 \n"
 252 "    MOV     R2, #0xF \n"
 253 "    MOV     R1, R8 \n"
 254 "    ADD     R0, SP, #4 \n"
 255 "    BL      sub_003FC064 \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_FF81DC24 \n"
 269 "    MOV     R2, R9 \n"
 270 "    MOV     R1, R5 \n"
 271 "    MOV     R0, R8 \n"
 272 "    BL      _Open \n"
 273 
 274 "loc_FFAB58F4:\n"
 275 "    CMN     R0, #1 \n"
 276 "    MOV     R5, R0 \n"
 277 "    STR     R0, [R7, #4] \n"
 278 "    BNE     loc_FFAB5930 \n"
 279 "    ADD     R0, R4, #0x58 \n"
 280 "    BL      sub_FF820584 \n"
 281 "    LDR     R1, [R7, #0x1C] \n"
 282 "    BL      sub_FF81E400 \n"
 283 "    LDR     R1, [R7, #0x14] \n"
 284 "    CMP     R1, #0 \n"
 285 "    BEQ     loc_FFAB5990 \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_FFAB5930:\n"
 292 "    LDR     R0, =0xF1EA8 \n"
 293 "    MOV     R2, #0x20 \n"
 294 "    ADD     R1, R4, #0x58 \n"
 295 "    BL      sub_003FC24C \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_FFAB5968 \n"
 307 "    LDR     R1, [R4, #8] \n"
 308 "    MOV     R0, R5 \n"
 309 "    BL      sub_FF8175A0 \n"
 310 "    CMP     R0, #0 \n"
 311 "    MOVEQ   R1, R4 \n"
 312 "    MOVEQ   R0, #7 \n"
 313 "    BEQ     loc_FFAB598C \n"
 314 
 315 "loc_FFAB5968:\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_FFAB5740 \n"
 324 "    MOV     R1, R4 \n"
 325 "    MOV     R0, #0 \n"
 326 
 327 "loc_FFAB598C:\n"
 328 "    BL      sub_FFAB5740 \n"
 329 
 330 "loc_FFAB5990:\n"
 331 "    ADD     SP, SP, #0x3C \n"
 332 "    LDMFD   SP!, {R4-R9,PC} \n"
 333 );
 334 }
 335 
 336 /*************************************************************/
 337 //** sub_FFAB5EE0_my @ 0xFFAB5EE0 - 0xFFAB5FC4, length=58
 338 void __attribute__((naked,noinline)) sub_FFAB5EE0_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_FFAB5F0C \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_FFAB5F28 \n"
 350 "    B       loc_FFAB5F1C \n"
 351 
 352 "loc_FFAB5F0C:\n"
 353 "    LDR     R2, =0x34A \n"
 354 "    LDR     R1, =0xFFAB5CEC /*'dwFWrite.c'*/ \n"
 355 "    MOV     R0, #0 \n"
 356 "    BL      _DebugAssert \n"
 357 
 358 "loc_FFAB5F1C:\n"
 359 "    MOV     R1, R5 \n"
 360 "    MOV     R0, #7 \n"
 361 "    B       loc_FFAB5FC0 \n"
 362 
 363 "loc_FFAB5F28:\n"
 364 "    LDR     R9, =0xBA84 \n"
 365 "    MOV     R4, R7 \n"
 366 
 367 "loc_FFAB5F30:\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_FFAB5F90 \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_FFAB5F1C \n"
 392 
 393 "loc_FFAB5F90:\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, =0xFFAB5CEC /*'dwFWrite.c'*/ \n"
 399 "    MOVCS   R0, #0 \n"
 400 "    BLCS    _DebugAssert \n"
 401 "    CMP     R4, #0 \n"
 402 "    BNE     loc_FFAB5F30 \n"
 403 "    LDR     R0, [R5] \n"
 404 "    MOV     R1, R5 \n"
 405 "    ADD     R0, R0, #1 \n"
 406 
 407 "loc_FFAB5FC0:\n"
 408 "    LDMFD   SP!, {R4-R10,LR} \n"
 409 "    B       sub_FFAB5740 \n"
 410 "    .ltorg\n" //+
 411 );
 412 }
 413 
 414 /*************************************************************/
 415 //** sub_FFAB5998_my @ 0xFFAB5998 - 0xFFAB59D8, length=17
 416 void __attribute__((naked,noinline)) sub_FFAB5998_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, =0xBA84 \n"
 422 "    TST     R0, #2 \n"
 423 "    SUB     SP, SP, #0x38 \n"
 424 "    BEQ     sub_FFAB5B00 \n"
 425 "    LDR     R0, [R5, #4] \n"
 426 "    CMN     R0, #1 \n"
 427 "    BEQ     sub_FFAB59EC \n"
 428 "    LDR     R1, [R4, #0x54] \n"
 429 "    LDR     R6, =0x9200003 \n"
 430 "    CMP     R1, #1 \n"
 431 "    BNE     loc_FFAB59D8 \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_FF8172F4 \n"
 440 "    B       sub_FFAB59DC \n"
 441 
 442 "loc_FFAB59D8:\n"
 443 "loc_D:\n"
 444 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 445 "    LDR     PC, =0xFFAB59DC \n"  // Continue in firmware
 446 );
 447 }

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