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

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

DEFINITIONS

This source file includes following definitions.
  1. log_fwt_msg
  2. filewritetask
  3. sub_FFA26268_my
  4. sub_FFA263B4_my
  5. sub_FFA264B0_my

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 
   4 // ifdef allows easy building with/without filewrite support for testing
   5 #ifdef CAM_HAS_FILEWRITETASK_HOOK
   6 
   7 // debug
   8 //#define FILEWRITE_DEBUG_LOG 1
   9 extern void _LogCameraEvent(int id,const char *fmt,...);
  10 
  11 typedef struct {
  12     unsigned int address;
  13     unsigned int length;
  14 } cam_ptp_data_chunk; //camera specific structure
  15 
  16 #define MAX_CHUNKS_FOR_FWT 3 //model specific
  17 /*
  18  * fwt_data_struct: defined here as it's camera dependent
  19  * unneeded members are designated with unkn
  20  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  21  * pdc is always required
  22  * name is not currently used
  23  */
  24 typedef struct
  25 {
  26     int unkn1[5]; // first value is message number, next seems to be total written, others unknown
  27     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_FWT];
  28     char name[32];
  29 } fwt_data_struct;
  30 
  31 #include "../../../generic/filewrite.c"
  32 
  33 #ifdef FILEWRITE_DEBUG_LOG
  34 void log_fwt_msg(fwt_data_struct *fwd)
  35 {
  36     int m=fwd->unkn1[0];
  37     _LogCameraEvent(0x20,"fw m:%d",m);
  38     _LogCameraEvent(0x20,"fw %s",fwd->name);
  39     // 4 because write stage messages start at 4 (not true for all cams)
  40     if(m >= 4 && m < (4+MAX_CHUNKS_FOR_FWT)) {
  41         _LogCameraEvent(0x20,"fw chunk adr:0x%08x l:0x%08x",fwd->pdc[m-4].address,fwd->pdc[m-4].length);
  42     }
  43     _LogCameraEvent(0x20,"fw u %08x %08x %08x %08x",fwd->unkn1[1],fwd->unkn1[2],fwd->unkn1[3],fwd->unkn1[4]);
  44 }
  45 #endif
  46 
  47 
  48 void __attribute__((naked,noinline)) filewritetask() { // FFA25FB4 "FileWriteTask"
  49 asm volatile (
  50 "                STMFD   SP!, {R1-R5,LR}\n"
  51 "                LDR     R4, =0x9314\n"
  52 "loc_FFA25FBC:\n"
  53 // jumptable FFA25FFC default entry
  54 "                LDR     R0, [R4,#0x10]\n"
  55 "                MOV     R2, #0\n"
  56 "                ADD     R1, SP, #8\n"
  57 "                BL      sub_FF826C30\n" // KerQueue.c 0
  58 "                CMP     R0, #0\n"
  59 "                BNE     loc_FFA25FEC\n"
  60 #ifdef FILEWRITE_DEBUG_LOG
  61 "ldr     r0, [sp,#8]\n"
  62 "bl log_fwt_msg\n"
  63 #endif
  64 "                LDR     R0, [SP,#8]\n"
  65 "                LDR     R1, [R0]\n"
  66 "                CMP     R1, #1\n"
  67 "                BNE     loc_FFA25FF4\n"
  68 "                LDR     R0, [R4,#8]\n"
  69 "                BL      sub_FF82711C\n" // GiveSemaphore
  70 "loc_FFA25FEC:\n"
  71 "                BL      _ExitTask\n"
  72 "                LDMFD   SP!, {R1-R5,PC}\n"
  73 "loc_FFA25FF4:\n"
  74 "                SUB     R1, R1, #2\n"
  75 "                CMP     R1, #5\n"
  76 "                ADDLS   PC, PC, R1,LSL#2\n"
  77 "                B       loc_FFA25FBC\n"
  78 "                B       loc_FFA2601C\n"
  79 "                B       loc_FFA26080\n"
  80 "                B       loc_FFA26088\n"
  81 "                B       loc_FFA26088\n"
  82 "                B       loc_FFA26088\n"
  83 "                B       loc_FFA26090\n"
  84 "loc_FFA2601C:\n"
  85 // jumptable FFA25FFC entry 0
  86 "                MOV     R0, #0\n"
  87 "                STR     R0, [SP]\n"
  88 "loc_FFA26024:\n"
  89 "                LDR     R0, [R4,#0x10]\n"
  90 "                MOV     R1, SP\n"
  91 "                BL      sub_FF826E74\n" // KerQueue.c 0
  92 "                LDR     R0, [SP]\n"
  93 "                CMP     R0, #0\n"
  94 "                BEQ     loc_FFA26050\n"
  95 "                LDR     R0, [R4,#0x10]\n"
  96 "                MOV     R2, #0\n"
  97 "                ADD     R1, SP, #4\n"
  98 "                BL      sub_FF826C30\n" // KerQueue.c 0
  99 "                B       loc_FFA26024\n"
 100 "loc_FFA26050:\n"
 101 "                LDR     R0, [R4]\n"
 102 "                CMN     R0, #1\n"
 103 "                BEQ     loc_FFA26074\n"
 104 //"                BL      _Close\n"
 105 "                BL      fwt_close\n" //+
 106 "                MVN     R0, #0\n"
 107 "                STR     R0, [R4]\n"
 108 "                LDR     R0, =0xCD788\n"
 109 "                BL      sub_FF855E18\n" // Mounter.c 0
 110 "                BL      sub_FF8543A4\n" // FileSem.c 136
 111 "loc_FFA26074:\n"
 112 "                LDR     R0, [R4,#0xC]\n"
 113 "                BL      sub_FF82711C\n" // GiveSemaphore
 114 "                B       loc_FFA25FBC\n"
 115 "loc_FFA26080:\n"
 116 // jumptable FFA25FFC entry 1
 117 "                BL      sub_FFA26268_my\n" //->
 118 "                B       loc_FFA25FBC\n"
 119 "loc_FFA26088:\n"
 120 // jumptable FFA25FFC entries 2-4
 121 "                BL      sub_FFA263B4_my\n" // dwFWrite.c 4 ->
 122 "                B       loc_FFA25FBC\n"
 123 "loc_FFA26090:\n"
 124 // jumptable FFA25FFC entry 5
 125 "                BL      sub_FFA264B0_my\n"
 126 "                B       loc_FFA25FBC\n"
 127 
 128     );
 129 }
 130 
 131 void __attribute__((naked,noinline)) sub_FFA26268_my( ) {
 132 asm volatile (
 133 "                STMFD   SP!, {R4-R8,LR}\n"
 134 "                MOV     R4, R0\n"
 135 "                ADD     R0, R0, #0x2C\n"
 136 "                SUB     SP, SP, #0x38\n"
 137 "                BL      sub_FF855E18\n" // Mounter.c 0
 138 "                MOV     R1, #0\n"
 139 "                BL      sub_FF854354\n"
 140 "                LDR     R0, [R4,#0xC]\n"
 141 "                BL      sub_FF8527FC\n"
 142 "                LDR     R7, [R4,#8]\n"
 143 "                LDR     R8, =0x1B6\n"
 144 "                ADD     R6, R4, #0x2C\n"
 145 "                LDR     R5, [R4,#0xC]\n"
 146 //hook start
 147       "STMFD SP!, {R4-R12,LR}\n"
 148       "MOV R0, R4\n"
 149       "BL filewrite_main_hook\n"
 150       "LDMFD SP!, {R4-R12,LR}\n"
 151 //hook end
 152 
 153 "                MOV     R0, R6\n"
 154 "                MOV     R1, R7\n"
 155 "                MOV     R2, R8\n"
 156 //"                BL      _Open\n"
 157 "                BL      fwt_open\n"
 158 "                LDR     PC,=0xFFA262AC\n" // jump back to ROM
 159 /*
 160 "                CMN     R0, #1\n"
 161 "                BNE     loc_FFA2630C\n"
 162 "                MOV     R0, R6\n"
 163 "                BL      sub_FF824190\n"
 164 "                MOV     R2, #0xF\n"
 165 "                MOV     R1, R6\n"
 166 "                MOV     R0, SP\n"
 167 "                BL      sub_FFACBD60\n"
 168 "                LDR     R0, =0x41FF\n"
 169 "                MOV     R1, #0\n"
 170 "                STRB    R1, [SP,#0xF]\n"
 171 "                STR     R0, [SP,#0x20]\n"
 172 "                MOV     R0, #0x10\n"
 173 "                ADD     R2, SP, #0x24\n"
 174 "                STMIA   R2, {R0,R1,R5}\n"
 175 "                ADD     R1, SP, #0x20\n"
 176 "                MOV     R0, SP\n"
 177 "                STR     R5, [SP,#0x30]\n"
 178 "                STR     R5, [SP,#0x34]\n"
 179 "                BL      sub_FF853C68\n"
 180 "                MOV     R2, R8\n"
 181 "                MOV     R1, R7\n"
 182 "                MOV     R0, R6\n"
 183 "                BL      _Open\n"
 184 "loc_FFA2630C:\n"
 185 "                LDR     R5, =0x9314\n"
 186 "                CMN     R0, #1\n"
 187 "                STR     R0, [R5]\n"
 188 "                BNE     loc_FFA26354\n"
 189 "                LDR     R0, [R5,#0x18]\n"
 190 "                CMP     R0, #0\n"
 191 "                BLXNE   R0\n"
 192 "                ADD     R0, R4, #0x2C\n"
 193 "                BL      sub_FF855E18\n" // Mounter.c 0
 194 "                BL      sub_FF8543A4\n" // FileSem.c 136
 195 "                LDR     R1, [R5,#0x14]\n"
 196 "                CMP     R1, #0\n"
 197 "                ADDNE   SP, SP, #0x38\n"
 198 "                LDMNEFD SP!, {R4-R8,LR}\n"
 199 "                LDRNE   R0, =0x9200001\n"
 200 "                BXNE    R1\n"
 201 "loc_FFA2634C:\n"
 202 "                ADD     SP, SP, #0x38\n"
 203 "                LDMFD   SP!, {R4-R8,PC}\n"
 204 "loc_FFA26354:\n"
 205 "                LDR     R0, =0xCD788\n"
 206 "                MOV     R2, #0x20\n"
 207 "                ADD     R1, R4, #0x2C\n"
 208 "                BL      sub_FFACBEC8\n"
 209 "                MOV     R1, R4\n"
 210 "                MOV     R0, #4\n"
 211 "                BL      sub_FFA25F0C\n"
 212 "                B       loc_FFA2634C\n"
 213 */
 214     );
 215 }
 216 
 217 void __attribute__((naked,noinline)) sub_FFA263B4_my( ) {
 218 asm volatile (
 219 "                STMFD   SP!, {R4-R10,LR}\n"
 220 "                MOV     R4, R0\n"
 221 "                LDR     R0, [R0]\n"
 222 "                CMP     R0, #4\n"
 223 "                LDREQ   R6, [R4,#0x18]\n"
 224 "                LDREQ   R7, [R4,#0x14]\n"
 225 "                BEQ     loc_FFA263F0\n"
 226 "                CMP     R0, #5\n"
 227 "                LDREQ   R6, [R4,#0x20]\n"
 228 "                LDREQ   R7, [R4,#0x1C]\n"
 229 "                BEQ     loc_FFA263F0\n"
 230 "                CMP     R0, #6\n"
 231 "                BNE     loc_FFA26404\n"
 232 "                LDR     R6, [R4,#0x28]\n"
 233 "                LDR     R7, [R4,#0x24]\n"
 234 "loc_FFA263F0:\n"
 235 "                CMP     R6, #0\n"
 236 "                BNE     loc_FFA26414\n"
 237 "loc_FFA263F8:\n"
 238 "                MOV     R1, R4\n"
 239 "                MOV     R0, #7\n"
 240 "                B       loc_FFA264A8\n"
 241 "loc_FFA26404:\n"
 242 "                LDR     R1, =0x20D\n"
 243 "                LDR     R0, =0xFFA26394\n" // "dwFWrite.c"
 244 "                BL      sub_FF81B284\n" // DebugAssert
 245 "                B       loc_FFA263F8\n"
 246 "loc_FFA26414:\n"
 247 "                LDR     R9, =0x9314\n"
 248 "                MOV     R5, R6\n"
 249 "loc_FFA2641C:\n"
 250 "                LDR     R0, [R4,#4]\n"
 251 "                CMP     R5, #0x1000000\n"
 252 "                MOVLS   R8, R5\n"
 253 "                MOVHI   R8, #0x1000000\n"
 254 "                BIC     R1, R0, #0xFF000000\n"
 255 "                CMP     R1, #0\n"
 256 "                BICNE   R0, R0, #0xFF000000\n"
 257 "                RSBNE   R0, R0, #0x1000000\n"
 258 "                CMPNE   R8, R0\n"
 259 "                MOVHI   R8, R0\n"
 260 "                LDR     R0, [R9]\n"
 261 "                MOV     R2, R8\n"
 262 "                MOV     R1, R7\n"
 263 //"                BL      _Write\n"
 264 "                BL      fwt_write\n"
 265 "                LDR     R1, [R4,#4]\n"
 266 "                CMP     R8, R0\n"
 267 "                ADD     R1, R1, R0\n"
 268 "                STR     R1, [R4,#4]\n"
 269 "                BEQ     loc_FFA2647C\n"
 270 "                LDR     R0, =0x10B1\n"
 271 "                BL      sub_FF877A6C\n" // IsControlEventActive
 272 "                LDR     R1, =0x9200005\n"
 273 "                STR     R1, [R4,#0x10]\n"
 274 "                B       loc_FFA263F8\n"
 275 "loc_FFA2647C:\n"
 276 "                SUB     R5, R5, R0\n"
 277 "                CMP     R5, R6\n"
 278 "                ADD     R7, R7, R0\n"
 279 "                LDRCS   R0, =0xFFA26394\n" // "dwFWrite.c"
 280 "                MOVCS   R1, #0x23C\n"
 281 "                BLCS    sub_FF81B284\n" // DebugAssert
 282 "                CMP     R5, #0\n"
 283 "                BNE     loc_FFA2641C\n"
 284 "                LDR     R0, [R4]\n"
 285 "                MOV     R1, R4\n"
 286 "                ADD     R0, R0, #1\n"
 287 "loc_FFA264A8:\n"
 288 "                LDMFD   SP!, {R4-R10,LR}\n"
 289 "                B       sub_FFA25F0C\n"
 290     );
 291 }
 292 
 293 void __attribute__((naked,noinline)) sub_FFA264B0_my( ) {
 294 asm volatile (
 295 "                STMFD   SP!, {R4,R5,LR}\n"
 296 "                LDR     R5, =0x9314\n"
 297 "                MOV     R4, R0\n"
 298 "                LDR     R0, [R5]\n"
 299 "                SUB     SP, SP, #0x1C\n"
 300 "                CMN     R0, #1\n"
 301 "                BEQ     loc_FFA264E4\n"
 302 //"                BL      _Close\n"
 303 "                BL      fwt_close\n"
 304 "                CMP     R0, #0\n"
 305 "                LDRNE   R0, =0x9200003\n"
 306 "                STRNE   R0, [R4,#0x10]\n"
 307 "                MVN     R0, #0\n"
 308 "                STR     R0, [R5]\n"
 309 "loc_FFA264E4:\n"
 310 "                LDR     PC, =0xFFA264E4\n" // jump back to firmware
 311 /*
 312 "                LDR     R0, [R4,#0x10]\n"
 313 "                TST     R0, #1\n"
 314 "                BNE     loc_FFA2652C\n"
 315 "                LDR     R0, =0x81FF\n"
 316 "                ADD     R1, SP, #4\n"
 317 "                STR     R0, [SP,#4]\n"
 318 "                MOV     R0, #0x20\n"
 319 "                STR     R0, [SP,#8]\n"
 320 "                LDR     R0, [R4,#4]\n"
 321 "                STR     R0, [SP,#0xC]\n"
 322 "                LDR     R0, [R4,#0xC]\n"
 323 "                STR     R0, [SP,#0x10]\n"
 324 "                LDR     R0, [R4,#0xC]\n"
 325 "                STR     R0, [SP,#0x14]\n"
 326 "                LDR     R0, [R4,#0xC]\n"
 327 "                STR     R0, [SP,#0x18]\n"
 328 "                ADD     R0, R4, #0x2C\n"
 329 "                BL      sub_FF853C68\n"
 330 "loc_FFA2652C:\n"
 331 "                LDR     R0, [R5,#0x18]\n"
 332 "                CMP     R0, #0\n"
 333 "                BLXNE   R0\n"
 334 "                ADD     R0, R4, #0x2C\n"
 335 "                BL      sub_FF855E18\n" // Mounter.c 0
 336 "                BL      sub_FF8543A4\n" // FileSem.c 136
 337 "                LDR     R1, [R5,#0x14]\n"
 338 "                CMP     R1, #0\n"
 339 "                LDRNE   R0, [R4,#0x10]\n"
 340 "                BLXNE   R1\n"
 341 "                ADD     SP, SP, #0x1C\n"
 342 "                LDMFD   SP!, {R4,R5,PC}\n"
 343 */
 344     );
 345 }
 346 #endif
 347 

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