root/platform/a470/sub/102c/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. CreateTask_spytask
  2. taskCreateHook
  3. boot
  4. sub_FFC001A4_my
  5. sub_FFC00FA0_my
  6. uHwSetup_my
  7. CreateTask_Startup_my
  8. task_Startup_my
  9. taskcreatePhySw_my
  10. init_file_modules_task
  11. sub_FFC57CDC_my
  12. sub_FFC3CA60_my
  13. sub_FFC3C89C_my
  14. sub_FFC3C62C_my

   1 /*
   2  * boot.c - auto-generated by CHDK code_gen.
   3  */
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 #include "core.h"
   7 
   8 const char * const new_sa = &_end;
   9 
  10 /* Ours stuff */
  11 extern long wrs_kernel_bss_start;
  12 extern long wrs_kernel_bss_end;
  13 
  14 /*----------------------------------------------------------------------
  15     CreateTask_spytask
  16 -----------------------------------------------------------------------*/
  17 void CreateTask_spytask()
  18 {
  19     _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);
  20 }
  21 
  22 void taskCreateHook(int *p) {
  23     p-=16;
  24     if (p[0]==(int)0xffc48dc0)  p[0]=(int)capt_seq_task;
  25     if (p[0]==(int)0xffc905d4)  p[0]=(int)exp_drv_task;
  26     if (p[0]==(int)0xffdc18e4)  p[0]=(int)filewritetask;
  27     if (p[0]==(int)0xffc5f114)  p[0]=(int)init_file_modules_task;
  28     if (p[0]==(int)0xffc458f4)  p[0]=(int)movie_record_task;
  29 }
  30 
  31 void boot()
  32 {
  33     long *canon_data_src = (void*)0xFFEABED8; //found with "romdata start" string
  34     long *canon_data_dst = (void*)0x1900;
  35     long canon_data_len = 0xEBF8 - 0x1900; // data_end - data_start
  36     long *canon_bss_start = (void*)0xEBF8; // just after data
  37     long canon_bss_len = 0xA5798 - 0xEBF8; // found using heapstart
  38 
  39     long i;
  40 
  41 
  42     // Enable CPU caches and MPU
  43     asm volatile (
  44     "MRC     p15, 0, R0,c1,c0\n"
  45     "ORR     R0, R0, #0x1000\n"
  46     "ORR     R0, R0, #4\n"
  47     "ORR     R0, R0, #1\n"
  48     "MCR     p15, 0, R0,c1,c0\n"
  49     :::"r0");
  50 
  51     for(i=0;i<canon_data_len/4;i++)
  52     canon_data_dst[i]=canon_data_src[i];
  53 
  54     for(i=0;i<canon_bss_len/4;i++)
  55     canon_bss_start[i]=0;
  56 
  57    *(int*)0x1930=(int)taskCreateHook;
  58    *(int*)0x1934=(int)taskCreateHook;
  59 
  60     // jump to init-sequence that follows the data-copy-routine
  61     asm volatile ("B      sub_FFC001A4_my\n");
  62 };
  63 
  64 
  65 /*************************************************************/
  66 //** sub_FFC001A4_my @ 0xFFC001A4 - 0xFFC0020C, length=27
  67 void __attribute__((naked,noinline)) sub_FFC001A4_my() {
  68 asm volatile (
  69 "    LDR     R0, =0xFFC0021C \n"
  70 "    MOV     R1, #0 \n"
  71 "    LDR     R3, =0xFFC00254 \n"
  72 
  73 "loc_FFC001B0:\n"
  74 "    CMP     R0, R3 \n"
  75 "    LDRCC   R2, [R0], #4 \n"
  76 "    STRCC   R2, [R1], #4 \n"
  77 "    BCC     loc_FFC001B0 \n"
  78 "    LDR     R0, =0xFFC00254 \n"
  79 "    MOV     R1, #0x4B0 \n"
  80 "    LDR     R3, =0xFFC00468 \n"
  81 
  82 "loc_FFC001CC:\n"
  83 "    CMP     R0, R3 \n"
  84 "    LDRCC   R2, [R0], #4 \n"
  85 "    STRCC   R2, [R1], #4 \n"
  86 "    BCC     loc_FFC001CC \n"
  87 "    MOV     R0, #0xD2 \n"
  88 "    MSR     CPSR_cxsf, R0 \n"
  89 "    MOV     SP, #0x1000 \n"
  90 "    MOV     R0, #0xD3 \n"
  91 "    MSR     CPSR_cxsf, R0 \n"
  92 "    MOV     SP, #0x1000 \n"
  93 "    LDR     R0, =0x6C4 \n"
  94 "    LDR     R2, =0xEEEEEEEE \n"
  95 "    MOV     R3, #0x1000 \n"
  96 
  97 "loc_FFC00200:\n"
  98 "    CMP     R0, R3 \n"
  99 "    STRCC   R2, [R0], #4 \n"
 100 "    BCC     loc_FFC00200 \n"
 101 "    BL      sub_FFC00FA0_my \n"  // --> Patched. Old value = 0xFFC00FA0.
 102 );
 103 }
 104 
 105 /*************************************************************/
 106 //** sub_FFC00FA0_my @ 0xFFC00FA0 - 0xFFC01040, length=41
 107 void __attribute__((naked,noinline)) sub_FFC00FA0_my() {
 108 asm volatile (
 109 "    STR     LR, [SP, #-4]! \n"
 110 "    SUB     SP, SP, #0x74 \n"
 111 "    MOV     R0, SP \n"
 112 "    MOV     R1, #0x74 \n"
 113 "    BL      sub_FFE4ECA0 \n"
 114 "    MOV     R0, #0x53000 \n"
 115 "    STR     R0, [SP, #4] \n"
 116 
 117 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 118 "    LDR     R0, =0xA5798 \n"
 119 #else
 120 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 121 "    LDR     R0, [R0]\n"      //
 122 #endif
 123 
 124 "    LDR     R2, =0x279C00 \n"
 125 "    LDR     R1, =0x272968 \n"
 126 "    STR     R0, [SP, #8] \n"
 127 "    SUB     R0, R1, R0 \n"
 128 "    ADD     R3, SP, #0xC \n"
 129 "    STR     R2, [SP] \n"
 130 "    STMIA   R3, {R0-R2} \n"
 131 "    MOV     R0, #0x22 \n"
 132 "    STR     R0, [SP, #0x18] \n"
 133 "    MOV     R0, #0x68 \n"
 134 "    STR     R0, [SP, #0x1C] \n"
 135 "    LDR     R0, =0x19B \n"
 136 "    MOV     R1, #0x64 \n"
 137 "    STRD    R0, [SP, #0x20] \n"
 138 "    MOV     R0, #0x78 \n"
 139 "    STRD    R0, [SP, #0x28] \n"
 140 "    MOV     R0, #0 \n"
 141 "    STR     R0, [SP, #0x30] \n"
 142 "    STR     R0, [SP, #0x34] \n"
 143 "    MOV     R0, #0x10 \n"
 144 "    STR     R0, [SP, #0x5C] \n"
 145 "    MOV     R0, #0x800 \n"
 146 "    STR     R0, [SP, #0x60] \n"
 147 "    MOV     R0, #0xA0 \n"
 148 "    STR     R0, [SP, #0x64] \n"
 149 "    MOV     R0, #0x280 \n"
 150 "    STR     R0, [SP, #0x68] \n"
 151 "    LDR     R1, =uHwSetup_my \n"  // --> Patched. Old value = 0xFFC04DA4.
 152 "    MOV     R0, SP \n"
 153 "    MOV     R2, #0 \n"
 154 "    BL      sub_FFC02D58 \n"
 155 "    ADD     SP, SP, #0x74 \n"
 156 "    LDR     PC, [SP], #4 \n"
 157 );
 158 }
 159 
 160 /*************************************************************/
 161 //** uHwSetup_my @ 0xFFC04DA4 - 0xFFC04E18, length=30
 162 void __attribute__((naked,noinline)) uHwSetup_my() {
 163 asm volatile (
 164 "    STMFD   SP!, {R4,LR} \n"
 165 "    BL      sub_FFC0094C \n"
 166 "    BL      sub_FFC0972C \n"
 167 "    CMP     R0, #0 \n"
 168 "    LDRLT   R0, =0xFFC04EB8 /*'dmSetup'*/ \n"
 169 "    BLLT    _err_init_task \n"
 170 "    BL      sub_FFC049C8 \n"
 171 "    CMP     R0, #0 \n"
 172 "    LDRLT   R0, =0xFFC04EC0 /*'termDriverInit'*/ \n"
 173 "    BLLT    _err_init_task \n"
 174 "    LDR     R0, =0xFFC04ED0 /*'/_term'*/ \n"
 175 "    BL      sub_FFC04AB4 \n"
 176 "    CMP     R0, #0 \n"
 177 "    LDRLT   R0, =0xFFC04ED8 /*'termDeviceCreate'*/ \n"
 178 "    BLLT    _err_init_task \n"
 179 "    LDR     R0, =0xFFC04ED0 /*'/_term'*/ \n"
 180 "    BL      sub_FFC03564 \n"
 181 "    CMP     R0, #0 \n"
 182 "    LDRLT   R0, =0xFFC04EEC /*'stdioSetup'*/ \n"
 183 "    BLLT    _err_init_task \n"
 184 "    BL      sub_FFC092B4 \n"
 185 "    CMP     R0, #0 \n"
 186 "    LDRLT   R0, =0xFFC04EF8 /*'stdlibSetup'*/ \n"
 187 "    BLLT    _err_init_task \n"
 188 "    BL      sub_FFC014B8 \n"
 189 "    CMP     R0, #0 \n"
 190 "    LDRLT   R0, =0xFFC04F04 /*'armlib_setup'*/ \n"
 191 "    BLLT    _err_init_task \n"
 192 "    LDMFD   SP!, {R4,LR} \n"
 193 "    B       CreateTask_Startup_my \n"  // --> Patched. Old value = 0xFFC0CD84.
 194 );
 195 }
 196 
 197 /*************************************************************/
 198 //** CreateTask_Startup_my @ 0xFFC0CD84 - 0xFFC0CDF0, length=28
 199 void __attribute__((naked,noinline)) CreateTask_Startup_my() {
 200 asm volatile (
 201 "    STMFD   SP!, {R3,LR} \n"
 202 //"  BL      _sub_FFC30BB0 \n"  // --> Nullsub call removed.
 203 "    BL      sub_FFC1978C \n"
 204 "    CMP     R0, #0 \n"
 205 "    BNE     loc_FFC0CDB4 \n"
 206 "    BL      sub_FFC30BA0 \n"
 207 "    CMP     R0, #0 \n"
 208 "    BNE     loc_FFC0CDB4 \n"
 209 "    LDR     R1, =0xC0220000 \n"
 210 "    MOV     R0, #0x44 \n"
 211 "    STR     R0, [R1, #0xA0] \n"
 212 
 213 "loc_FFC0CDB0:\n"
 214 "    B       loc_FFC0CDB0 \n"
 215 
 216 "loc_FFC0CDB4:\n"
 217 //"  BL      _sub_FFC30BB8 \n"  // --> Nullsub call removed.
 218 //"  BL      _sub_FFC30BB4 \n"  // --> Nullsub call removed.
 219 "    BL      sub_FFC17B14 \n"
 220 "    LDR     R1, =0x2CE000 \n"
 221 "    MOV     R0, #0 \n"
 222 "    BL      sub_FFC17D5C \n"
 223 "    BL      sub_FFC17D08 /*_EnableDispatch*/ \n"
 224 "    MOV     R3, #0 \n"
 225 "    STR     R3, [SP] \n"
 226 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFFC0CD28.
 227 "    MOV     R2, #0 \n"
 228 "    MOV     R1, #0x19 \n"
 229 "    LDR     R0, =0xFFC0CDFC /*'Startup'*/ \n"
 230 "    BL      _CreateTask \n"
 231 "    MOV     R0, #0 \n"
 232 "    LDMFD   SP!, {R12,PC} \n"
 233 );
 234 }
 235 
 236 /*************************************************************/
 237 //** task_Startup_my @ 0xFFC0CD28 - 0xFFC0CD7C, length=22
 238 void __attribute__((naked,noinline)) task_Startup_my() {
 239 asm volatile (
 240 "    STMFD   SP!, {R4,LR} \n"
 241 "    BL      sub_FFC051BC \n"
 242 "    BL      sub_FFC12B1C \n"
 243 "    BL      sub_FFC0FDFC \n"
 244 //"  BL      _sub_FFC31020 \n"  // --> Nullsub call removed.
 245 "    BL      sub_FFC19994 \n"
 246 //"  BL      _sub_FFC19854 \n"  // load DISKBOOT.BIN
 247 "    BL      CreateTask_spytask\n" // added
 248 "    BL      sub_FFC5BCB4 \n"
 249 "    BL      sub_FFC199E4 \n"
 250 "    BL      sub_FFC17054 \n"
 251 "    BL      sub_FFC19B4C \n"
 252 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFFC118D8. Checks buttons and acts accordingly
 253 "    BL      sub_FFC14A18 \n"
 254 "    BL      sub_FFC19B64 \n"
 255 //"  BL      _sub_FFC0FBD8 \n"  // --> Nullsub call removed.
 256 "    BL      sub_FFC10DAC \n"
 257 "    BL      sub_FFC19554 \n"
 258 "    BL      sub_FFC11408 \n"
 259 "    BL      sub_FFC10CAC \n"
 260 "    BL      sub_FFC1A4CC \n"
 261 "    BL      sub_FFC10C68 \n"
 262 "    LDMFD   SP!, {R4,LR} \n"
 263 );
 264 }
 265 
 266 /*************************************************************/
 267 //** taskcreatePhySw_my @ 0xFFC118D8 - 0xFFC1191C, length=18
 268 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 269 asm volatile (
 270 "    STMFD   SP!, {R3-R5,LR} \n"
 271 "    LDR     R4, =0x1BE4 \n"
 272 "    LDR     R0, [R4, #0x10] \n"
 273 "    CMP     R0, #0 \n"
 274 "    BNE     loc_FFC1190C \n"
 275 "    MOV     R3, #0 \n"
 276 "    STR     R3, [SP] \n"
 277 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFFC118A4.
 278 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw so we don't have to do stack switch
 279 "    MOV     R1, #0x17 \n"
 280 "    LDR     R0, =0xFFC11B00 /*'PhySw'*/ \n"
 281 "    BL      sub_FFC0BBB8 /*_CreateTaskStrictly*/ \n"
 282 "    STR     R0, [R4, #0x10] \n"
 283 
 284 "loc_FFC1190C:\n"
 285 "    BL      sub_FFC14488 \n"
 286 "    LDR     R1, =0x100C8 \n"
 287 "    LDMFD   SP!, {R3-R5,LR} \n"
 288 "    MOV     R0, #0 \n"
 289 "    B       sub_FFC55808 /*_OpLog.Start_FW*/ \n"
 290 );
 291 }
 292 
 293 /*************************************************************/
 294 //** init_file_modules_task @ 0xFFC5F114 - 0xFFC5F148, length=14
 295 void __attribute__((naked,noinline)) init_file_modules_task() {
 296 asm volatile (
 297 "    STMFD   SP!, {R4-R6,LR} \n"
 298 "    BL      sub_FFC57CB0 \n"
 299 "    LDR     R5, =0x5006 \n"
 300 "    MOVS    R4, R0 \n"
 301 "    MOVNE   R1, #0 \n"
 302 "    MOVNE   R0, R5 \n"
 303 "    BLNE    _PostLogicalEventToUI \n"
 304 "    BL      sub_FFC57CDC_my \n"  // --> Patched. Old value = 0xFFC57CDC.
 305 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 306 "    CMP     R4, #0 \n"
 307 "    MOVEQ   R0, R5 \n"
 308 "    LDMEQFD SP!, {R4-R6,LR} \n"
 309 "    MOVEQ   R1, #0 \n"
 310 "    BEQ     _PostLogicalEventToUI \n"
 311 "    LDMFD   SP!, {R4-R6,PC} \n"
 312 );
 313 }
 314 
 315 /*************************************************************/
 316 //** sub_FFC57CDC_my @ 0xFFC57CDC - 0xFFC57D14, length=15
 317 void __attribute__((naked,noinline)) sub_FFC57CDC_my() {
 318 asm volatile (
 319 "    STMFD   SP!, {R4,LR} \n"
 320 "    BL      sub_FFC3CA60_my \n"  // --> Patched. Old value = 0xFFC3CA60.
 321 "    LDR     R4, =0x55D0 \n"
 322 "    LDR     R0, [R4, #4] \n"
 323 "    CMP     R0, #0 \n"
 324 "    BNE     loc_FFC57D0C \n"
 325 "    BL      sub_FFC660A4 \n"
 326 "    BL      sub_FFCDCC74 \n"
 327 "    BL      sub_FFC660A4 \n"
 328 "    BL      sub_FFC3A450 \n"
 329 "    BL      sub_FFC660B4 \n"
 330 "    BL      sub_FFCDCD40 \n"
 331 
 332 "loc_FFC57D0C:\n"
 333 "    MOV     R0, #1 \n"
 334 "    STR     R0, [R4] \n"
 335 "    LDMFD   SP!, {R4,PC} \n"
 336 );
 337 }
 338 
 339 /*************************************************************/
 340 //** sub_FFC3CA60_my @ 0xFFC3CA60 - 0xFFC3CAF8, length=39
 341 void __attribute__((naked,noinline)) sub_FFC3CA60_my() {
 342 asm volatile (
 343 "    STMFD   SP!, {R4-R6,LR} \n"
 344 "    MOV     R6, #0 \n"
 345 "    MOV     R0, R6 \n"
 346 "    BL      sub_FFC3C520 \n"
 347 "    LDR     R4, =0x111A8 \n"
 348 "    MOV     R5, #0 \n"
 349 "    LDR     R0, [R4, #0x38] \n"
 350 "    BL      sub_FFC3CF54 \n"
 351 "    CMP     R0, #0 \n"
 352 "    LDREQ   R0, =0x287C \n"
 353 "    STREQ   R5, [R0, #0x10] \n"
 354 "    STREQ   R5, [R0, #0x14] \n"
 355 "    STREQ   R5, [R0, #0x18] \n"
 356 "    MOV     R0, R6 \n"
 357 "    BL      sub_FFC3C560 \n"
 358 "    MOV     R0, R6 \n"
 359 "    BL      sub_FFC3C89C_my \n"  // --> Patched. Old value = 0xFFC3C89C.
 360 "    MOV     R5, R0 \n"
 361 "    MOV     R0, R6 \n"
 362 "    BL      sub_FFC3C908 \n"
 363 "    LDR     R1, [R4, #0x3C] \n"
 364 "    AND     R2, R5, R0 \n"
 365 "    CMP     R1, #0 \n"
 366 "    MOV     R0, #0 \n"
 367 "    MOVEQ   R0, #0x80000001 \n"
 368 "    BEQ     loc_FFC3CAF4 \n"
 369 "    LDR     R3, [R4, #0x2C] \n"
 370 "    CMP     R3, #2 \n"
 371 "    MOVEQ   R0, #4 \n"
 372 "    CMP     R1, #5 \n"
 373 "    ORRNE   R0, R0, #1 \n"
 374 "    BICEQ   R0, R0, #1 \n"
 375 "    CMP     R2, #0 \n"
 376 "    BICEQ   R0, R0, #2 \n"
 377 "    ORREQ   R0, R0, #0x80000000 \n"
 378 "    BICNE   R0, R0, #0x80000000 \n"
 379 "    ORRNE   R0, R0, #2 \n"
 380 
 381 "loc_FFC3CAF4:\n"
 382 "    STR     R0, [R4, #0x40] \n"
 383 "    LDMFD   SP!, {R4-R6,PC} \n"
 384 );
 385 }
 386 
 387 /*************************************************************/
 388 //** sub_FFC3C89C_my @ 0xFFC3C89C - 0xFFC3C904, length=27
 389 void __attribute__((naked,noinline)) sub_FFC3C89C_my() {
 390 asm volatile (
 391 "    STMFD   SP!, {R4-R6,LR} \n"
 392 "    LDR     R5, =0x287C \n"
 393 "    MOV     R6, R0 \n"
 394 "    LDR     R0, [R5, #0x14] \n"
 395 "    CMP     R0, #0 \n"
 396 "    MOVNE   R0, #1 \n"
 397 "    LDMNEFD SP!, {R4-R6,PC} \n"
 398 "    MOV     R0, #0x17 \n"
 399 "    MUL     R1, R0, R6 \n"
 400 "    LDR     R0, =0x111A8 \n"
 401 "    ADD     R4, R0, R1, LSL#2 \n"
 402 "    LDR     R0, [R4, #0x38] \n"
 403 "    MOV     R1, R6 \n"
 404 "    BL      sub_FFC3C62C_my \n"  // --> Patched. Old value = 0xFFC3C62C.
 405 "    CMP     R0, #0 \n"
 406 "    LDMEQFD SP!, {R4-R6,PC} \n"
 407 "    LDR     R0, [R4, #0x38] \n"
 408 "    MOV     R1, R6 \n"
 409 "    BL      sub_FFC3C794 \n"
 410 "    CMP     R0, #0 \n"
 411 "    LDMEQFD SP!, {R4-R6,PC} \n"
 412 "    MOV     R0, R6 \n"
 413 "    BL      sub_FFC3C128 \n"
 414 "    CMP     R0, #0 \n"
 415 "    MOVNE   R1, #1 \n"
 416 "    STRNE   R1, [R5, #0x14] \n"
 417 "    LDMFD   SP!, {R4-R6,PC} \n"
 418 );
 419 }
 420 
 421 /*************************************************************/
 422 //** sub_FFC3C62C_my @ 0xFFC3C62C - 0xFFC3C790, length=90
 423 void __attribute__((naked,noinline)) sub_FFC3C62C_my() {
 424 asm volatile (
 425 "    STMFD   SP!, {R4-R8,LR} \n"
 426 "    MOV     R8, R0 \n"
 427 "    MOV     R0, #0x17 \n"
 428 "    MUL     R1, R0, R1 \n"
 429 "    LDR     R0, =0x111A8 \n"
 430 "    MOV     R6, #0 \n"
 431 "    ADD     R7, R0, R1, LSL#2 \n"
 432 "    LDR     R0, [R7, #0x3C] \n"
 433 "    MOV     R5, #0 \n"
 434 "    CMP     R0, #6 \n"
 435 "    ADDLS   PC, PC, R0, LSL#2 \n"
 436 "    B       loc_FFC3C778 \n"
 437 "    B       loc_FFC3C690 \n"
 438 "    B       loc_FFC3C678 \n"
 439 "    B       loc_FFC3C678 \n"
 440 "    B       loc_FFC3C678 \n"
 441 "    B       loc_FFC3C678 \n"
 442 "    B       loc_FFC3C770 \n"
 443 "    B       loc_FFC3C678 \n"
 444 
 445 "loc_FFC3C678:\n"
 446 "    MOV     R2, #0 \n"
 447 "    MOV     R1, #0x200 \n"
 448 "    MOV     R0, #3 \n"
 449 "    BL      _exmem_ualloc \n"
 450 "    MOVS    R4, R0 \n"
 451 "    BNE     loc_FFC3C698 \n"
 452 
 453 "loc_FFC3C690:\n"
 454 "    MOV     R0, #0 \n"
 455 "    LDMFD   SP!, {R4-R8,PC} \n"
 456 
 457 "loc_FFC3C698:\n"
 458 "    LDR     R12, [R7, #0x4C] \n"
 459 "    MOV     R3, R4 \n"
 460 "    MOV     R2, #1 \n"
 461 "    MOV     R1, #0 \n"
 462 "    MOV     R0, R8 \n"
 463 "    BLX     R12 \n"
 464 "    CMP     R0, #1 \n"
 465 "    BNE     loc_FFC3C6C4 \n"
 466 "    MOV     R0, #3 \n"
 467 "    BL      _exmem_ufree \n"
 468 "    B       loc_FFC3C690 \n"
 469 
 470 "loc_FFC3C6C4:\n"
 471 "    MOV     R0, R8 \n"
 472 "    BL      sub_FFCF97DC \n"
 473 
 474 "    MOV     R1, R4\n"              //  pointer to MBR in R1
 475 "    BL      mbr_read_dryos\n"      //  total sectors count in R0 before and after call
 476 
 477 // Start of DataGhost's FAT32 autodetection code
 478 // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage
 479 // According to the code below, we can use R1, R2, R3 and R12.
 480 // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing
 481 // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :)
 482 "    MOV     R12, R4\n"             // Copy the MBR start address so we have something to work with
 483 "    MOV     LR, R4\n"              // Save old offset for MBR signature
 484 "    MOV     R1, #1\n"              // Note the current partition number
 485 "    B       dg_sd_fat32_enter\n"   // We actually need to check the first partition as well, no increments yet!
 486 "dg_sd_fat32:\n"
 487 "    CMP     R1, #4\n"              // Did we already see the 4th partition?
 488 "    BEQ     dg_sd_fat32_end\n"     // Yes, break. We didn't find anything, so don't change anything.
 489 "    ADD     R12, R12, #0x10\n"     // Second partition
 490 "    ADD     R1, R1, #1\n"          // Second partition for the loop
 491 "dg_sd_fat32_enter:\n"
 492 "    LDRB    R2, [R12, #0x1BE]\n"   // Partition status
 493 "    LDRB    R3, [R12, #0x1C2]\n"   // Partition type (FAT32 = 0xB)
 494 "    CMP     R3, #0xB\n"            // Is this a FAT32 partition?
 495 "    CMPNE   R3, #0xC\n"            // Not 0xB, is it 0xC (FAT32 LBA) then?
 496 "    CMPNE   R3, #0x7\n"            // exFat?
 497 "    BNE     dg_sd_fat32\n"         // No, it isn't. Loop again.
 498 "    CMP     R2, #0x00\n"           // It is, check the validity of the partition type
 499 "    CMPNE   R2, #0x80\n"
 500 "    BNE     dg_sd_fat32\n"         // Invalid, go to next partition
 501                                     // This partition is valid, it's the first one, bingo!
 502 "    MOV     R4, R12\n"             // Move the new MBR offset for the partition detection.
 503 
 504 "dg_sd_fat32_end:\n"
 505 // End of DataGhost's FAT32 autodetection code
 506 
 507 "    LDRB    R1, [R4, #0x1C9] \n"
 508 "    LDRB    R3, [R4, #0x1C8] \n"
 509 "    LDRB    R12, [R4, #0x1CC] \n"
 510 "    MOV     R1, R1, LSL#24 \n"
 511 "    ORR     R1, R1, R3, LSL#16 \n"
 512 "    LDRB    R3, [R4, #0x1C7] \n"
 513 "    LDRB    R2, [R4, #0x1BE] \n"
 514 //"  LDRB    LR, [R4, #0x1FF] \n"
 515 "    ORR     R1, R1, R3, LSL#8 \n"
 516 "    LDRB    R3, [R4, #0x1C6] \n"
 517 "    CMP     R2, #0 \n"
 518 "    CMPNE   R2, #0x80 \n"
 519 "    ORR     R1, R1, R3 \n"
 520 "    LDRB    R3, [R4, #0x1CD] \n"
 521 "    MOV     R3, R3, LSL#24 \n"
 522 "    ORR     R3, R3, R12, LSL#16 \n"
 523 "    LDRB    R12, [R4, #0x1CB] \n"
 524 "    ORR     R3, R3, R12, LSL#8 \n"
 525 "    LDRB    R12, [R4, #0x1CA] \n"
 526 "    ORR     R3, R3, R12 \n"
 527 //"  LDRB    R12, [R4, #0x1FE] \n"  // Replaced, see below
 528 //mod start
 529 "    LDRB    R12, [LR,#0x1FE]\n"           // New! First MBR signature byte (0x55)
 530 "    LDRB    LR, [LR,#0x1FF]\n"            //      Last MBR signature byte (0xAA)
 531 //mod end
 532 "    MOV     R4, #0 \n"
 533 "    BNE     loc_FFC3C74C \n"
 534 "    CMP     R0, R1 \n"
 535 "    BCC     loc_FFC3C74C \n"
 536 "    ADD     R2, R1, R3 \n"
 537 "    CMP     R2, R0 \n"
 538 "    CMPLS   R12, #0x55 \n"
 539 "    CMPEQ   LR, #0xAA \n"
 540 "    MOVEQ   R6, R1 \n"
 541 "    MOVEQ   R5, R3 \n"
 542 "    MOVEQ   R4, #1 \n"
 543 
 544 "loc_FFC3C74C:\n"
 545 "    MOV     R0, #3 \n"
 546 "    BL      _exmem_ufree \n"
 547 "    CMP     R4, #0 \n"
 548 "    BNE     loc_FFC3C784 \n"
 549 "    MOV     R6, #0 \n"
 550 "    MOV     R0, R8 \n"
 551 "    BL      sub_FFCF97DC \n"
 552 "    MOV     R5, R0 \n"
 553 "    B       loc_FFC3C784 \n"
 554 
 555 "loc_FFC3C770:\n"
 556 "    MOV     R5, #0x40 \n"
 557 "    B       loc_FFC3C784 \n"
 558 
 559 "loc_FFC3C778:\n"
 560 "    MOV     R1, #0x374 \n"
 561 "    LDR     R0, =0xFFC3C620 /*'Mounter.c'*/ \n"
 562 "    BL      _DebugAssert \n"
 563 
 564 "loc_FFC3C784:\n"
 565 "    STR     R6, [R7, #0x44]! \n"
 566 "    MOV     R0, #1 \n"
 567 "    STR     R5, [R7, #4] \n"
 568 "    LDMFD   SP!, {R4-R8,PC} \n"
 569 );
 570 }

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