root/platform/sx400is/sub/100b/filewrite.c

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

DEFINITIONS

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

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