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

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFA759B0_my
  3. sub_FFA76070_my
  4. sub_FFA75B3C_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 @ 0xFFA75CC4 - 0xFFA75E64, length=105
  45 void __attribute__((naked,noinline)) filewritetask() {
  46 asm volatile (
  47 "    STMFD   SP!, {R1-R7,LR} \n"
  48 "    LDR     R5, =0xA988 \n"
  49 "    MOV     R6, #0 \n"
  50 
  51 "loc_FFA75CD0:\n"
  52 "    LDR     R0, [R5, #0x10] \n"
  53 "    MOV     R2, #0 \n"
  54 "    ADD     R1, SP, #8 \n"
  55 "    BL      sub_003F7418 /*_ReceiveMessageQueue*/ \n"
  56 "    CMP     R0, #0 \n"
  57 "    LDRNE   R1, =0x3EF \n"
  58 "    LDRNE   R0, =0xFFA75E90 /*'dwFWrite.c'*/ \n"
  59 "    BLNE    _DebugAssert \n"
  60 "    LDR     R0, [SP, #8] \n"
  61 "    LDR     R1, [R0] \n"
  62 "    CMP     R1, #0xD \n"
  63 "    ADDCC   PC, PC, R1, LSL#2 \n"
  64 "    B       loc_FFA75CD0 \n"
  65 "    B       loc_FFA75E58 \n"
  66 "    B       loc_FFA75E58 \n"
  67 "    B       loc_FFA75E58 \n"
  68 "    B       loc_FFA75E58 \n"
  69 "    B       loc_FFA75E58 \n"
  70 "    B       loc_FFA75E58 \n"
  71 "    B       loc_FFA75E58 \n"
  72 "    B       loc_FFA75E60 \n"
  73 "    B       loc_FFA75D38 \n"
  74 "    B       loc_FFA75DD4 \n"
  75 "    B       loc_FFA75E04 \n"
  76 "    B       loc_FFA75DA0 \n"
  77 "    B       loc_FFA75DCC \n"
  78 
  79 "loc_FFA75D38:\n"
  80 "    MOV     R4, R5 \n"
  81 "    STR     R6, [SP] \n"
  82 
  83 "loc_FFA75D40:\n"
  84 "    LDR     R0, [R4, #0x10] \n"
  85 "    MOV     R1, SP \n"
  86 "    BL      sub_003F765C /*_GetNumberOfPostedMessages*/ \n"
  87 "    LDR     R0, [SP] \n"
  88 "    CMP     R0, #0 \n"
  89 "    BEQ     loc_FFA75D6C \n"
  90 "    LDR     R0, [R4, #0x10] \n"
  91 "    MOV     R2, #0 \n"
  92 "    ADD     R1, SP, #4 \n"
  93 "    BL      sub_003F7418 /*_ReceiveMessageQueue*/ \n"
  94 "    B       loc_FFA75D40 \n"
  95 
  96 "loc_FFA75D6C:\n"
  97 "    LDR     R0, [R4, #4] \n"
  98 "    CMN     R0, #1 \n"
  99 "    BEQ     loc_FFA75D94 \n"
 100 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 101 "    MVN     R0, #0 \n"
 102 "    STR     R0, [R4, #4] \n"
 103 "    LDR     R0, =0xED380 \n"
 104 "    BL      sub_FF877840 \n"
 105 "    MOV     R1, #0 \n"
 106 "    BL      sub_FF875730 \n"
 107 
 108 "loc_FFA75D94:\n"
 109 "    LDR     R0, [R4, #0xC] \n"
 110 "    BL      _GiveSemaphore \n"
 111 "    B       loc_FFA75CD0 \n"
 112 
 113 "loc_FFA75DA0:\n"
 114 "    MOV     R4, R0 \n"
 115 "    ADD     R0, R0, #0x58 \n"
 116 "    BL      sub_FF877840 \n"
 117 "    MOV     R1, #0 \n"
 118 "    BL      sub_FF8755F4 \n"
 119 "    LDR     R0, [R4, #0xC] \n"
 120 "    BL      sub_FF8746AC \n"
 121 "    ADD     R0, R4, #0x58 \n"
 122 
 123 //mod start
 124 "    LDR R3, =ignore_current_write\n" // !!
 125 "    LDR R3, [R3]\n"
 126 "    CMP R3, #0\n"
 127 "    BNE loc_A\n" // skip creating directory
 128 //mod end
 129 "    BL      sub_FF82DD58 \n"
 130 "    ADD     R0, R4, #0x58 \n"
 131 "    B       loc_FFA75E38 \n"
 132 
 133 "loc_FFA75DCC:\n"
 134 "    BL      sub_FFA759B0_my \n"  // --> Patched. Old value = 0xFFA759B0. Open stage
 135 "    B       loc_FFA75CD0 \n"
 136 
 137 "loc_FFA75DD4:\n"
 138 "    LDR     R1, [R0, #4] \n"
 139 "    MOV     R4, R0 \n"
 140 "    LDR     R0, [R5, #4] \n"
 141 "    MOV     R2, #0 \n"
 142 "    BL      fwt_lseek \n"  // --> Patched. Old value = _lseek.
 143 "    CMN     R0, #1 \n"
 144 "    LDREQ   R0, =0x9200013 \n"
 145 "    MOVEQ   R1, R4 \n"
 146 "    STREQ   R0, [R4, #0x10] \n"
 147 "    MOVEQ   R0, #7 \n"
 148 "    BLEQ    sub_FFA758F0 \n"
 149 "    B       loc_FFA75CD0 \n"
 150 
 151 "loc_FFA75E04:\n"
 152 "    MOV     R4, R0 \n"
 153 "    LDRSB   R0, [R0, #0x58] \n"
 154 "    CMP     R0, #0 \n"
 155 "    BEQ     loc_FFA75CD0 \n"
 156 "    STRB    R0, [SP, #4] \n"
 157 "    ADD     R0, R4, #0x58 \n"
 158 "    STRB    R6, [SP, #5] \n"
 159 "    BL      sub_FF877840 \n"
 160 "    MOV     R1, #0 \n"
 161 "    BL      sub_FF8755F4 \n"
 162 
 163 //mod start
 164 "    LDR R3, =ignore_current_write\n" // !!
 165 "    LDR R3, [R3]\n"
 166 "    CMP R3, #0\n"
 167 "    BNE loc_B\n" // skip flushing the cache
 168 //mod end
 169 
 170 "    ADD     R0, SP, #4 \n"
 171 "    BL      sub_FF8746C4 \n"
 172 "loc_B:\n"
 173 "    ADD     R0, R4, #0x58 \n"
 174 
 175 "loc_FFA75E38:\n"
 176 "loc_A:\n"
 177 "    BL      sub_FF877840 \n"
 178 "    LDR     R1, [R5, #0x18] \n"
 179 "    BL      sub_FF875730 \n"
 180 "    LDR     R1, [R5, #0x14] \n"
 181 "    CMP     R1, #0 \n"
 182 "    LDRNE   R0, [R4, #0x10] \n"
 183 "    BLXNE   R1 \n"
 184 "    B       loc_FFA75CD0 \n"
 185 
 186 "loc_FFA75E58:\n"
 187 "    BL      sub_FFA76070_my \n"  // --> Patched. Old value = 0xFFA76070. Write stage
 188 "    B       loc_FFA75CD0 \n"
 189 
 190 "loc_FFA75E60:\n"
 191 "    BL      sub_FFA75B3C_my \n"  // --> Patched. Old value = 0xFFA75B3C. Close stage
 192 "    B       loc_FFA75CD0 \n"
 193 );
 194 }
 195 
 196 /*************************************************************/
 197 //** sub_FFA759B0_my @ 0xFFA759B0 - 0xFFA75B38, length=99
 198 void __attribute__((naked,noinline)) sub_FFA759B0_my() {
 199 asm volatile (
 200 "    STMFD   SP!, {R4-R8,LR} \n"
 201 "    MOV     R4, R0 \n"
 202 //hook placed here to avoid conditional branch a few instructions below (watch out for registers!)
 203 //"  MOV   R0, R4\n"      //data block start, commented out as R0 is already holding what we need
 204 "    BL filewrite_main_hook\n"
 205 "    MOV     R0, R4\n"      //restore register(s)
 206 //hook end
 207 "    LDR     R0, [R0, #0x4C] \n"
 208 "    SUB     SP, SP, #0x38 \n"
 209 "    TST     R0, #1 \n"
 210 "    BEQ     loc_FFA75B0C \n"
 211 "    ADD     R0, R4, #0x58 \n"
 212 "    BL      sub_FF877840 \n"
 213 "    MOV     R1, #0 \n"
 214 "    BL      sub_FF8755F4 \n"
 215 "    LDR     R0, [R4, #0xC] \n"
 216 "    BL      sub_FF8746AC \n"
 217 "    LDR     R0, [R4, #0x4C] \n"
 218 "    LDR     R5, =0x301 \n"
 219 "    TST     R0, #0x10 \n"
 220 "    MOVNE   R5, #9 \n"
 221 "    BNE     loc_FFA759FC \n"
 222 "    TST     R0, #0x40 \n"
 223 "    MOVNE   R5, #1 \n"
 224 
 225 "loc_FFA759FC:\n"
 226 "    TST     R0, #0x20 \n"
 227 "    BNE     loc_FFA75A10 \n"
 228 "    LDR     R0, [R4, #0x54] \n"
 229 "    CMP     R0, #1 \n"
 230 "    BNE     loc_FFA75A14 \n"
 231 
 232 "loc_FFA75A10:\n"
 233 "    ORR     R5, R5, #0x8000 \n"
 234 
 235 "loc_FFA75A14:\n"
 236 "    LDR     R8, =0x1B6 \n"
 237 "    ADD     R7, R4, #0x58 \n"
 238 "    LDR     R6, [R4, #0xC] \n"
 239 "    MOV     R2, R8 \n"
 240 "    MOV     R1, R5 \n"
 241 "    MOV     R0, R7 \n"
 242 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 243 "    CMN     R0, #1 \n"
 244 "    BNE     loc_FFA75A94 \n"
 245 "    MOV     R0, R7 \n"
 246 "    BL      sub_FF82DD58 \n"
 247 "    MOV     R2, #0xF \n"
 248 "    MOV     R1, R7 \n"
 249 "    MOV     R0, SP \n"
 250 "    BL      sub_003FC550 \n"
 251 "    MOV     R0, #0 \n"
 252 "    LDR     R1, =0x41FF \n"
 253 "    STRB    R0, [SP, #0xF] \n"
 254 "    STR     R1, [SP, #0x20] \n"
 255 "    MOV     R1, #0x10 \n"
 256 "    STR     R0, [SP, #0x28] \n"
 257 "    STR     R1, [SP, #0x24] \n"
 258 "    ADD     R1, SP, #0x20 \n"
 259 "    MOV     R0, SP \n"
 260 "    STR     R6, [SP, #0x2C] \n"
 261 "    STR     R6, [SP, #0x30] \n"
 262 "    STR     R6, [SP, #0x34] \n"
 263 "    BL      sub_FF874F70 \n"
 264 "    MOV     R2, R8 \n"
 265 "    MOV     R1, R5 \n"
 266 "    MOV     R0, R7 \n"
 267 "    BL      _Open \n"
 268 
 269 "loc_FFA75A94:\n"
 270 "    LDR     R6, =0xA988 \n"
 271 "    CMN     R0, #1 \n"
 272 "    MOV     R5, R0 \n"
 273 "    STR     R0, [R6, #4] \n"
 274 "    BNE     loc_FFA75AD4 \n"
 275 "    ADD     R0, R4, #0x58 \n"
 276 "    BL      sub_FF877840 \n"
 277 "    LDR     R1, [R6, #0x18] \n"
 278 "    BL      sub_FF875730 \n"
 279 "    LDR     R1, [R6, #0x14] \n"
 280 "    CMP     R1, #0 \n"
 281 "    BEQ     loc_FFA75B34 \n"
 282 "    ADD     SP, SP, #0x38 \n"
 283 "    LDMFD   SP!, {R4-R8,LR} \n"
 284 "    LDR     R0, =0x9200001 \n"
 285 "    BX      R1 \n"
 286 
 287 "loc_FFA75AD4:\n"
 288 "    LDR     R0, =0xED380 \n"
 289 "    MOV     R2, #0x20 \n"
 290 "    ADD     R1, R4, #0x58 \n"
 291 "    BL      sub_003FC738 \n"
 292 
 293 //mod start
 294 "    LDR R3, =current_write_ignored\n"
 295 "    LDR R3, [R3]\n"
 296 "    CMP R3, #0\n"
 297 "    BNE loc_C\n" // jump over the next block
 298 //mod end
 299 
 300 "    LDR     R0, [R4, #0x4C] \n"
 301 "    TST     R0, #0x80 \n"
 302 "    BEQ     loc_FFA75B0C \n"
 303 "    LDR     R1, [R4, #8] \n"
 304 "    MOV     R0, R5 \n"
 305 "    BL      sub_FF82DA28 \n"
 306 "    CMP     R0, #0 \n"
 307 "    MOVEQ   R1, R4 \n"
 308 "    MOVEQ   R0, #7 \n"
 309 "    BEQ     loc_FFA75B30 \n"
 310 
 311 "loc_FFA75B0C:\n"
 312 "loc_C:\n"
 313 "    LDR     R0, [R4, #0x4C] \n"
 314 "    TST     R0, #0x40 \n"
 315 "    LDREQ   R0, [R4, #4] \n"
 316 "    CMPEQ   R0, #0 \n"
 317 "    MOVNE   R1, R4 \n"
 318 "    MOVNE   R0, #9 \n"
 319 "    BLNE    sub_FFA758F0 \n"
 320 "    MOV     R1, R4 \n"
 321 "    MOV     R0, #0 \n"
 322 
 323 "loc_FFA75B30:\n"
 324 "    BL      sub_FFA758F0 \n"
 325 
 326 "loc_FFA75B34:\n"
 327 "    ADD     SP, SP, #0x38 \n"
 328 "    LDMFD   SP!, {R4-R8,PC} \n"
 329 );
 330 }
 331 
 332 /*************************************************************/
 333 //** sub_FFA76070_my @ 0xFFA76070 - 0xFFA7614C, length=56
 334 void __attribute__((naked,noinline)) sub_FFA76070_my() {
 335 asm volatile (
 336 "    STMFD   SP!, {R4-R10,LR} \n"
 337 "    MOV     R5, R0 \n"
 338 "    LDR     R0, [R0] \n"
 339 "    CMP     R0, #6 \n"
 340 "    BHI     loc_FFA7609C \n"
 341 "    ADD     R0, R5, R0, LSL#3 \n"
 342 "    LDR     R8, [R0, #0x14]! \n"
 343 "    LDR     R7, [R0, #4] \n"
 344 "    CMP     R7, #0 \n"
 345 "    BNE     loc_FFA760B4 \n"
 346 "    B       loc_FFA760A8 \n"
 347 
 348 "loc_FFA7609C:\n"
 349 "    MOV     R1, #0x344 \n"
 350 "    LDR     R0, =0xFFA75E90 /*'dwFWrite.c'*/ \n"
 351 "    BL      _DebugAssert \n"
 352 
 353 "loc_FFA760A8:\n"
 354 "    MOV     R1, R5 \n"
 355 "    MOV     R0, #7 \n"
 356 "    B       loc_FFA76148 \n"
 357 
 358 "loc_FFA760B4:\n"
 359 "    LDR     R9, =0xA988 \n"
 360 "    MOV     R4, R7 \n"
 361 
 362 "loc_FFA760BC:\n"
 363 "    LDR     R0, [R5, #4] \n"
 364 "    CMP     R4, #0x1000000 \n"
 365 "    MOVLS   R6, R4 \n"
 366 "    MOVHI   R6, #0x1000000 \n"
 367 "    BIC     R1, R0, #0xFF000000 \n"
 368 "    CMP     R1, #0 \n"
 369 "    BICNE   R0, R0, #0xFF000000 \n"
 370 "    RSBNE   R0, R0, #0x1000000 \n"
 371 "    CMPNE   R6, R0 \n"
 372 "    MOVHI   R6, R0 \n"
 373 "    LDR     R0, [R9, #4] \n"
 374 "    MOV     R2, R6 \n"
 375 "    MOV     R1, R8 \n"
 376 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 377 "    LDR     R1, [R5, #4] \n"
 378 "    CMP     R6, R0 \n"
 379 "    ADD     R1, R1, R0 \n"
 380 "    STR     R1, [R5, #4] \n"
 381 "    BEQ     loc_FFA7611C \n"
 382 "    CMN     R0, #1 \n"
 383 "    LDRNE   R0, =0x9200015 \n"
 384 "    LDREQ   R0, =0x9200005 \n"
 385 "    STR     R0, [R5, #0x10] \n"
 386 "    B       loc_FFA760A8 \n"
 387 
 388 "loc_FFA7611C:\n"
 389 "    SUB     R4, R4, R0 \n"
 390 "    CMP     R4, R7 \n"
 391 "    LDRCS   R1, =0x36F \n"
 392 "    ADD     R8, R8, R0 \n"
 393 "    LDRCS   R0, =0xFFA75E90 /*'dwFWrite.c'*/ \n"
 394 "    BLCS    _DebugAssert \n"
 395 "    CMP     R4, #0 \n"
 396 "    BNE     loc_FFA760BC \n"
 397 "    LDR     R0, [R5] \n"
 398 "    MOV     R1, R5 \n"
 399 "    ADD     R0, R0, #1 \n"
 400 
 401 "loc_FFA76148:\n"
 402 "    LDMFD   SP!, {R4-R10,LR} \n"
 403 "    B       sub_FFA758F0 \n"
 404 "    .ltorg\n" //+
 405 );
 406 }
 407 
 408 /*************************************************************/
 409 //** sub_FFA75B3C_my @ 0xFFA75B3C - 0xFFA75B7C, length=17
 410 void __attribute__((naked,noinline)) sub_FFA75B3C_my() {
 411 asm volatile (
 412 "    STMFD   SP!, {R4-R6,LR} \n"
 413 "    MOV     R4, R0 \n"
 414 "    LDR     R0, [R0, #0x4C] \n"
 415 "    LDR     R5, =0xA988 \n"
 416 "    TST     R0, #2 \n"
 417 "    SUB     SP, SP, #0x38 \n"
 418 "    BEQ     sub_FFA75CA4 \n"
 419 "    LDR     R0, [R5, #4] \n"
 420 "    CMN     R0, #1 \n"
 421 "    BEQ     sub_FFA75B90 \n"
 422 "    LDR     R1, [R4, #0x54] \n"
 423 "    LDR     R6, =0x9200003 \n"
 424 "    CMP     R1, #1 \n"
 425 "    BNE     loc_FFA75B7C \n"
 426 //mod start
 427 "    LDR R3, =current_write_ignored\n"
 428 "    LDR R3, [R3]\n"
 429 "    CMP R3, #0\n"
 430 "    BNE loc_D\n" // jump over the next block
 431 //mod end
 432 
 433 "    BL      sub_FF82D77C \n"
 434 "    B       sub_FFA75B80 \n"
 435 
 436 "loc_FFA75B7C:\n"
 437 "loc_D:\n"
 438 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 439 "    LDR     PC, =0xFFA75B80 \n"  // Continue in firmware
 440 );
 441 }

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