root/platform/g10/sub/102a/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. task_blinker
  2. CreateTask_Blinker
  3. taskCreateHook
  4. taskCreateHook2
  5. boot
  6. sub_FF8101A0_my
  7. sub_FF810F94_my
  8. sub_FF814D8C_my
  9. taskcreate_Startup_my
  10. task_Startup_my
  11. busy_loop
  12. CreateTask_spytask
  13. CreateTask_PhySw
  14. init_file_modules_task
  15. sub_FF878098_my
  16. sub_FF859C00_my
  17. sub_FF859A3C_my
  18. sub_FF8597CC_my
  19. JogDial_task_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 // run blinker task
   9 //#define BLINKER 1
  10 #ifdef BLINKER
  11 #include "stdlib.h"
  12 #include "gui.h"
  13 #include "../../../../core/gui_draw.h"
  14 #endif
  15 
  16 const char * const new_sa = &_end;
  17 
  18 #define LED_ISO  (void*) 0xC02200D0 // G10 ISO select dial LED
  19 #define LED_DP   (void*) 0xC02200D4 // G10 direct print button LED
  20 #define LED_ECL  (void*) 0xC02200D8 // G10 exposure compensation dial LED
  21 #define LED_PWR  (void*) 0xC02200DC // G10 power LED
  22 
  23 extern void task_CaptSeq();
  24 extern void task_InitFileModules();
  25 extern void task_RotaryEncoder();
  26 extern void task_MovieRecord();
  27 extern void task_ExpDrv();
  28 extern void task_FileWrite();
  29 
  30 // Forward declarations
  31 void CreateTask_PhySw();
  32 void CreateTask_spytask();
  33 extern volatile int jogdial_stopped;
  34 void JogDial_task_my(void);
  35 
  36 #ifdef BLINKER
  37 void __attribute__((naked,noinline)) task_blinker() {
  38 
  39 int pwr_led_count = 0 ;
  40 int blue_led_count = 0 ;
  41 int gui_mode, gui_mode_flag = GUI_MODE_NONE ;
  42 
  43 volatile long *pwr_LED = (void*)LED_PWR;
  44 volatile long *blue_LED = (void*)LED_DP;
  45 
  46         _SleepTask(2000);
  47 
  48         while(1){
  49 
  50             gui_mode = gui_get_mode() ;
  51 
  52             if(( (gui_mode == GUI_MODE_ALT)  && (gui_mode_flag != GUI_MODE_ALT) ) || ( (gui_mode == GUI_MODE_NONE)  && (gui_mode_flag != GUI_MODE_NONE) ) )
  53             {
  54                 gui_mode_flag = gui_mode ;
  55                 blue_led_count = 10 ;
  56                 *blue_LED = 0x46;
  57             }
  58             if ( blue_led_count > 0 )
  59             {
  60                 if ( --blue_led_count == 0 )
  61                 {
  62                     *blue_LED = 0x44;
  63                 }
  64             }
  65 
  66             if ( pwr_led_count == 2 )
  67             {
  68                 *pwr_LED = 0x44;
  69             }
  70             if ( --pwr_led_count <= 0 )
  71             {
  72                 pwr_led_count = 20 ;
  73                 *pwr_LED = 0x46;
  74             }
  75 
  76             _SleepTask(100);
  77         }
  78 };
  79 
  80 void CreateTask_Blinker() {
  81         _CreateTask("Blinker", 0x1, 0x200, task_blinker, 0);
  82 };
  83 #endif
  84 
  85 void taskCreateHook(int *p) {
  86     p-=17;
  87 
  88     if (p[0]==(int)task_InitFileModules) p[0]=(int)init_file_modules_task;
  89     if (p[0]==(int)task_MovieRecord)     p[0]=(int)movie_record_task;
  90     if (p[0]==(int)task_CaptSeq)         p[0]=(int)capt_seq_task;
  91     if (p[0]==(int)task_ExpDrv)          p[0]=(int)exp_drv_task;
  92     if (p[0]==(int)task_RotaryEncoder)   p[0]=(int)JogDial_task_my;
  93     if (p[0]==(int)task_FileWrite)       p[0]=(int)filewritetask;
  94 }
  95 
  96 void taskCreateHook2(int *p) {
  97     p-=17;
  98     if (p[0]==(int)task_InitFileModules) p[0]=(int)init_file_modules_task;
  99     if (p[0]==(int)task_ExpDrv)          p[0]=(int)exp_drv_task;
 100     if (p[0]==(int)task_FileWrite)       p[0]=(int)filewritetask;
 101 }
 102 
 103 /*----------------------------------------------------------------------
 104     boot()
 105 
 106     Main entry point for the CHDK code
 107 -----------------------------------------------------------------------*/
 108 
 109 /*************************************************************/
 110 //** boot @ 0xFF81000C - 0xFF810160, length=86
 111 void __attribute__((naked,noinline)) boot() {
 112 asm volatile (
 113 "    LDR     R1, =0xC0410000 \n"
 114 "    MOV     R0, #0 \n"
 115 "    STR     R0, [R1] \n"
 116 "    MOV     R1, #0x78 \n"
 117 "    MCR     p15, 0, R1, c1, c0 \n"
 118 "    MOV     R1, #0 \n"
 119 "    MCR     p15, 0, R1, c7, c10, 4 \n"
 120 "    MCR     p15, 0, R1, c7, c5 \n"
 121 "    MCR     p15, 0, R1, c7, c6 \n"
 122 "    MOV     R0, #0x3D \n"
 123 "    MCR     p15, 0, R0, c6, c0 \n"
 124 "    MOV     R0, #0xC000002F \n"
 125 "    MCR     p15, 0, R0, c6, c1 \n"
 126 "    MOV     R0, #0x35 \n"
 127 "    MCR     p15, 0, R0, c6, c2 \n"
 128 "    MOV     R0, #0x40000035 \n"
 129 "    MCR     p15, 0, R0, c6, c3 \n"
 130 "    MOV     R0, #0x80000017 \n"
 131 "    MCR     p15, 0, R0, c6, c4 \n"
 132 "    LDR     R0, =0xFF80002D \n"
 133 "    MCR     p15, 0, R0, c6, c5 \n"
 134 "    MOV     R0, #0x34 \n"
 135 "    MCR     p15, 0, R0, c2, c0 \n"
 136 "    MOV     R0, #0x34 \n"
 137 "    MCR     p15, 0, R0, c2, c0, 1 \n"
 138 "    MOV     R0, #0x34 \n"
 139 "    MCR     p15, 0, R0, c3, c0 \n"
 140 "    LDR     R0, =0x3333330 \n"
 141 "    MCR     p15, 0, R0, c5, c0, 2 \n"
 142 "    LDR     R0, =0x3333330 \n"
 143 "    MCR     p15, 0, R0, c5, c0, 3 \n"
 144 "    MRC     p15, 0, R0, c1, c0 \n"
 145 "    ORR     R0, R0, #0x1000 \n"
 146 "    ORR     R0, R0, #4 \n"
 147 "    ORR     R0, R0, #1 \n"
 148 "    MCR     p15, 0, R0, c1, c0 \n"
 149 "    MOV     R1, #0x80000006 \n"
 150 "    MCR     p15, 0, R1, c9, c1 \n"
 151 "    MOV     R1, #6 \n"
 152 "    MCR     p15, 0, R1, c9, c1, 1 \n"
 153 "    MRC     p15, 0, R1, c1, c0 \n"
 154 "    ORR     R1, R1, #0x50000 \n"
 155 "    MCR     p15, 0, R1, c1, c0 \n"
 156 "    LDR     R2, =0xC0200000 \n"
 157 "    MOV     R1, #1 \n"
 158 "    STR     R1, [R2, #0x10C] \n"
 159 "    MOV     R1, #0xFF \n"
 160 "    STR     R1, [R2, #0xC] \n"
 161 "    STR     R1, [R2, #0x1C] \n"
 162 "    STR     R1, [R2, #0x2C] \n"
 163 "    STR     R1, [R2, #0x3C] \n"
 164 "    STR     R1, [R2, #0x4C] \n"
 165 "    STR     R1, [R2, #0x5C] \n"
 166 "    STR     R1, [R2, #0x6C] \n"
 167 "    STR     R1, [R2, #0x7C] \n"
 168 "    STR     R1, [R2, #0x8C] \n"
 169 "    STR     R1, [R2, #0x9C] \n"
 170 "    STR     R1, [R2, #0xAC] \n"
 171 "    STR     R1, [R2, #0xBC] \n"
 172 "    STR     R1, [R2, #0xCC] \n"
 173 "    STR     R1, [R2, #0xDC] \n"
 174 "    STR     R1, [R2, #0xEC] \n"
 175 "    STR     R1, [R2, #0xFC] \n"
 176 "    LDR     R1, =0xC0400008 \n"
 177 "    LDR     R2, =0x430005 \n"
 178 "    STR     R2, [R1] \n"
 179 "    MOV     R1, #1 \n"
 180 "    LDR     R2, =0xC0243100 \n"
 181 "    STR     R2, [R1] \n"
 182 "    LDR     R2, =0xC0242010 \n"
 183 "    LDR     R1, [R2] \n"
 184 "    ORR     R1, R1, #1 \n"
 185 "    STR     R1, [R2] \n"
 186 "    LDR     R0, =0xFFBA09DC \n"
 187 "    LDR     R1, =0x1900 \n"
 188 "    LDR     R3, =0x10834 \n"
 189 
 190 "loc_FF81013C:\n"
 191 "    CMP     R1, R3 \n"
 192 "    LDRCC   R2, [R0], #4 \n"
 193 "    STRCC   R2, [R1], #4 \n"
 194 "    BCC     loc_FF81013C \n"
 195 "    LDR     R1, =0xEEECC \n"
 196 "    MOV     R2, #0 \n"
 197 
 198 "loc_FF810154:\n"
 199 "    CMP     R3, R1 \n"
 200 "    STRCC   R2, [R3], #4 \n"
 201 "    BCC     loc_FF810154 \n"
 202 "    B       sub_FF8101A0_my \n"  // --> Patched. Old value = 0xFF8101A0.
 203 );
 204 }
 205 
 206 /*************************************************************/
 207 //** sub_FF8101A0_my @ 0xFF8101A0 - 0xFF810208, length=27
 208 void __attribute__((naked,noinline)) sub_FF8101A0_my() {
 209 
 210     *(int*)0x1930=(int)taskCreateHook; 
 211     *(int*)0x1934=(int)taskCreateHook2; 
 212     *(int*)0x1938=(int)taskCreateHook;
 213 
 214     // Power ON/OFF detection  G10 @FF84A8D0   replacement  for correct power-on.
 215     *(int*)(0x25CC+0x04)= (*(int*)0xC02200F8)&1 ? 0x100000 : 0x200000; // replacement  for correct power-on.
 216     
 217 asm volatile (
 218 "    LDR     R0, =0xFF810218 \n"
 219 "    MOV     R1, #0 \n"
 220 "    LDR     R3, =0xFF810250 \n"
 221 
 222 "loc_FF8101AC:\n"
 223 "    CMP     R0, R3 \n"
 224 "    LDRCC   R2, [R0], #4 \n"
 225 "    STRCC   R2, [R1], #4 \n"
 226 "    BCC     loc_FF8101AC \n"
 227 "    LDR     R0, =0xFF810250 \n"
 228 "    MOV     R1, #0x4B0 \n"
 229 "    LDR     R3, =0xFF810464 \n"
 230 
 231 "loc_FF8101C8:\n"
 232 "    CMP     R0, R3 \n"
 233 "    LDRCC   R2, [R0], #4 \n"
 234 "    STRCC   R2, [R1], #4 \n"
 235 "    BCC     loc_FF8101C8 \n"
 236 "    MOV     R0, #0xD2 \n"
 237 "    MSR     CPSR_cxsf, R0 \n"
 238 "    MOV     SP, #0x1000 \n"
 239 "    MOV     R0, #0xD3 \n"
 240 "    MSR     CPSR_cxsf, R0 \n"
 241 "    MOV     SP, #0x1000 \n"
 242 "    LDR     R0, =0x6C4 \n"
 243 "    LDR     R2, =0xEEEEEEEE \n"
 244 "    MOV     R3, #0x1000 \n"
 245 
 246 "loc_FF8101FC:\n"
 247 "    CMP     R0, R3 \n"
 248 "    STRCC   R2, [R0], #4 \n"
 249 "    BCC     loc_FF8101FC \n"
 250 "    BL      sub_FF810F94_my \n"  // --> Patched. Old value = 0xFF810F94.
 251 );
 252 }
 253 
 254 /*************************************************************/
 255 //** sub_FF810F94_my @ 0xFF810F94 - 0xFF811040, length=44
 256 void __attribute__((naked,noinline)) sub_FF810F94_my() {
 257 asm volatile (
 258 "    STR     LR, [SP, #-4]! \n"
 259 "    SUB     SP, SP, #0x74 \n"
 260 "    MOV     R0, SP \n"
 261 "    MOV     R1, #0x74 \n"
 262 "    BL      sub_FFB05244 \n"
 263 "    MOV     R0, #0x53000 \n"
 264 "    STR     R0, [SP, #4] \n"
 265 
 266 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 267 "    LDR     R0, =0xEEECC \n"
 268 #else
 269 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 270 "    LDR     R0, [R0]\n"      // 
 271 #endif
 272 
 273 "    LDR     R2, =0x379C00 \n"
 274 "    LDR     R1, =0x3724A8 \n"
 275 "    STR     R0, [SP, #8] \n"
 276 "    SUB     R0, R1, R0 \n"
 277 "    ADD     R3, SP, #0xC \n"
 278 "    STR     R2, [SP] \n"
 279 "    STMIA   R3, {R0-R2} \n"
 280 "    MOV     R0, #0x22 \n"
 281 "    STR     R0, [SP, #0x18] \n"
 282 "    MOV     R0, #0x68 \n"
 283 "    STR     R0, [SP, #0x1C] \n"
 284 "    LDR     R0, =0x19B \n"
 285 "    LDR     R1, =sub_FF814D8C_my \n"  // --> Patched. Old value = 0xFF814D8C.
 286 "    STR     R0, [SP, #0x20] \n"
 287 "    MOV     R0, #0x96 \n"
 288 "    STR     R0, [SP, #0x24] \n"
 289 "    MOV     R0, #0x78 \n"
 290 "    STR     R0, [SP, #0x28] \n"
 291 "    MOV     R0, #0x64 \n"
 292 "    STR     R0, [SP, #0x2C] \n"
 293 "    MOV     R0, #0 \n"
 294 "    STR     R0, [SP, #0x30] \n"
 295 "    STR     R0, [SP, #0x34] \n"
 296 "    MOV     R0, #0x10 \n"
 297 "    STR     R0, [SP, #0x5C] \n"
 298 "    MOV     R0, #0x800 \n"
 299 "    STR     R0, [SP, #0x60] \n"
 300 "    MOV     R0, #0xA0 \n"
 301 "    STR     R0, [SP, #0x64] \n"
 302 "    MOV     R0, #0x280 \n"
 303 "    STR     R0, [SP, #0x68] \n"
 304 "    MOV     R0, SP \n"
 305 "    MOV     R2, #0 \n"
 306 "    BL      sub_FF812D38 \n"
 307 "    ADD     SP, SP, #0x74 \n"
 308 "    LDR     PC, [SP], #4 \n"
 309 );
 310 }
 311 
 312 /*************************************************************/
 313 //** sub_FF814D8C_my @ 0xFF814D8C - 0xFF814E00, length=30
 314 void __attribute__((naked,noinline)) sub_FF814D8C_my() {
 315 asm volatile (
 316 "    STMFD   SP!, {R4,LR} \n"
 317 "    BL      sub_FF810940 \n"
 318 "    BL      sub_FF81901C \n"
 319 "    CMP     R0, #0 \n"
 320 "    LDRLT   R0, =0xFF814EA0 /*'dmSetup'*/ \n"
 321 "    BLLT    _err_init_task \n"
 322 "    BL      sub_FF8149B4 \n"
 323 "    CMP     R0, #0 \n"
 324 "    LDRLT   R0, =0xFF814EA8 /*'termDriverInit'*/ \n"
 325 "    BLLT    _err_init_task \n"
 326 "    LDR     R0, =0xFF814EB8 /*'/_term'*/ \n"
 327 "    BL      sub_FF814A9C \n"
 328 "    CMP     R0, #0 \n"
 329 "    LDRLT   R0, =0xFF814EC0 /*'termDeviceCreate'*/ \n"
 330 "    BLLT    _err_init_task \n"
 331 "    LDR     R0, =0xFF814EB8 /*'/_term'*/ \n"
 332 "    BL      sub_FF813548 \n"
 333 "    CMP     R0, #0 \n"
 334 "    LDRLT   R0, =0xFF814ED4 /*'stdioSetup'*/ \n"
 335 "    BLLT    _err_init_task \n"
 336 "    BL      sub_FF818BA4 \n"
 337 "    CMP     R0, #0 \n"
 338 "    LDRLT   R0, =0xFF814EE0 /*'stdlibSetup'*/ \n"
 339 "    BLLT    _err_init_task \n"
 340 "    BL      sub_FF811478 \n"
 341 "    CMP     R0, #0 \n"
 342 "    LDRLT   R0, =0xFF814EEC /*'armlib_setup'*/ \n"
 343 "    BLLT    _err_init_task \n"
 344 "    LDMFD   SP!, {R4,LR} \n"
 345 "    B       taskcreate_Startup_my \n"  // --> Patched. Old value = 0xFF81C1A8.
 346 );
 347 }
 348 
 349 /*************************************************************/
 350 //** taskcreate_Startup_my @ 0xFF81C1A8 - 0xFF81C228, length=33
 351 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 352 asm volatile (
 353 "    STMFD   SP!, {R3,LR} \n"
 354 //"  BL      _sub_FF84A8C8 \n"  // --> Nullsub call removed.
 355 "    BL      sub_FF82A16C \n"
 356 "    CMP     R0, #0 \n"
 357 "    BNE     loc_FF81C1EC \n"
 358 "    BL      sub_FF823100 \n"
 359 "    CMP     R0, #0 \n"
 360 "    BNE     loc_FF81C1EC \n"
 361 "    BL      sub_FF84A8B0 \n"
 362 "    CMP     R0, #0 \n"
 363 "    BNE     loc_FF81C1EC \n"
 364 "    BL      sub_FF821168 \n"
 365 "    LDR     R1, =0xC0220000 \n"
 366 "    MOV     R0, #0x44 \n"
 367 "    STR     R0, [R1, #0x1C] \n"
 368 "    BL      sub_FF821354 \n"
 369 
 370 "loc_FF81C1E8:\n"
 371 "    B       loc_FF81C1E8 \n"
 372 
 373 "loc_FF81C1EC:\n"
 374 //"  BL      _sub_FF84A8D0 \n"  // removed for corrected power-on/off
 375 //"  BL      _sub_FF84A8CC \n"  // --> Nullsub call removed.
 376 "    BL      sub_FF8282FC \n"
 377 "    LDR     R1, =0x3CE000 \n"
 378 "    MOV     R0, #0 \n"
 379 "    BL      sub_FF828744 \n"
 380 "    BL      sub_FF8284F0 \n"
 381 "    MOV     R3, #0 \n"
 382 "    STR     R3, [SP] \n"
 383 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF81C144.
 384 "    MOV     R2, #0 \n"
 385 "    MOV     R1, #0x19 \n"
 386 "    LDR     R0, =0xFF81C234 /*'Startup'*/ \n"
 387 "    BL      _CreateTask \n"
 388 "    MOV     R0, #0 \n"
 389 "    LDMFD   SP!, {R12,PC} \n"
 390 );
 391 }
 392 
 393 /*************************************************************/
 394 //** task_Startup_my @ 0xFF81C144 - 0xFF81C1A4, length=25
 395 void __attribute__((naked,noinline)) task_Startup_my() {
 396     *((volatile int *) LED_PWR) = 0x46;
 397 asm volatile (
 398 "    STMFD   SP!, {R4,LR} \n"
 399 "    BL      sub_FF8153CC \n"
 400 "    BL      sub_FF822B38 \n"
 401 "    BL      sub_FF820E28 \n"
 402 //"  BL      _sub_FF84B1A0 \n"  // --> Nullsub call removed.
 403 "    BL      sub_FF82A374 \n"
 404 //"  BL      _sub_FF82A234 \n"  // skip starting diskboot.bin
 405 "    BL      sub_FF87F158 \n"
 406 "    BL      sub_FF81FAA0 \n"
 407 "    BL      sub_FF82A3C4 \n"
 408 "    BL      sub_FF8278FC \n"
 409 "    BL      sub_FF82A530 \n"
 410 );
 411     CreateTask_spytask();
 412 asm volatile (
 413 "    BL      CreateTask_PhySw \n"  // --> Patched. Old value = 0xFF8218CC.
 414 );
 415 #ifdef BLINKER
 416    CreateTask_Blinker();
 417 #endif
 418 asm volatile (
 419 "    BL      sub_FF82503C \n"
 420 "    BL      sub_FF82A548 \n"
 421 //"  BL      _sub_FF81EF04 \n"  // --> Nullsub call removed.
 422 "    BL       busy_loop \n"   
 423 "    BL      sub_FF820738 \n"
 424 "    BL      sub_FF829F48 \n"
 425 "    BL      sub_FF820DD8 \n"
 426 "    BL      sub_FF820644 \n"
 427 "    BL      sub_FF81FAD4 \n"
 428 "    BL      sub_FF82B068 \n"
 429 "    BL      sub_FF82061C \n"
 430 "    LDMFD   SP!, {R4,LR} \n"
 431 "    B       sub_FF815490 \n"
 432 );
 433 }
 434 void __attribute__((naked,noinline)) busy_loop() {  // loop hack that allows startup with battery door open
 435   asm volatile (
 436 "   STMFD   SP!, {R4-R6,LR} \n"
 437 "   LDR     R0, =0x400000 \n"
 438 "loop1: \n"
 439 "   nop\n"
 440 "   SUBS   R0,R0,#1 \n"
 441 "   BNE    loop1 \n"
 442 "   LDMFD   SP!, {R4-R6,PC} \n"
 443     );
 444 }
 445 
 446 void CreateTask_spytask() { 
 447    _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);
 448 };
 449 
 450 
 451 /*************************************************************/
 452 //** CreateTask_PhySw @ 0xFF8218CC - 0xFF82191C, length=21
 453 void __attribute__((naked,noinline)) CreateTask_PhySw() {
 454 asm volatile (
 455 "    STMFD   SP!, {R3-R5,LR} \n"
 456 "    LDR     R4, =0x1C20 \n"
 457 "    LDR     R0, [R4, #0x10] \n"
 458 "    CMP     R0, #0 \n"
 459 "    BNE     loc_FF821900 \n"
 460 "    MOV     R3, #0 \n"
 461 "    STR     R3, [SP] \n"
 462 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF821898.
 463 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw
 464 "    MOV     R1, #0x17 \n"
 465 "    LDR     R0, =0xFF821AD4 /*'PhySw'*/ \n"
 466 "    BL      sub_FF828544 /*_CreateTaskStrictly*/ \n"
 467 "    STR     R0, [R4, #0x10] \n"
 468 
 469 "loc_FF821900:\n"
 470 "    BL      sub_FF84B338 \n"
 471 "    BL      sub_FF8249CC \n"
 472 "    BL      sub_FF8230A4 /*_IsFactoryMode_FW*/ \n"
 473 "    CMP     R0, #0 \n"
 474 "    LDREQ   R1, =0x11CC4 \n"
 475 "    LDMEQFD SP!, {R3-R5,LR} \n"
 476 "    BEQ     sub_FF875BFC /*_OpLog.Start_FW*/ \n"
 477 "    LDMFD   SP!, {R3-R5,PC} \n"
 478 );
 479 }
 480 
 481 //================init file modules task =========================================
 482 
 483 /*************************************************************/
 484 //** init_file_modules_task @ 0xFF882EA8 - 0xFF882EDC, length=14
 485 void __attribute__((naked,noinline)) init_file_modules_task() {
 486 asm volatile (
 487 "    STMFD   SP!, {R4-R6,LR} \n"
 488 "    BL      sub_FF87806C \n"
 489 "    LDR     R5, =0x5006 \n"
 490 "    MOVS    R4, R0 \n"
 491 "    MOVNE   R1, #0 \n"
 492 "    MOVNE   R0, R5 \n"
 493 "    BLNE    _PostLogicalEventToUI \n"
 494 "    BL      sub_FF878098_my \n"  // --> Patched. Old value = 0xFF878098.
 495 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 496 "    CMP     R4, #0 \n"
 497 "    MOVEQ   R0, R5 \n"
 498 "    LDMEQFD SP!, {R4-R6,LR} \n"
 499 "    MOVEQ   R1, #0 \n"
 500 "    BEQ     _PostLogicalEventToUI \n"
 501 "    LDMFD   SP!, {R4-R6,PC} \n"
 502 );
 503 }
 504 
 505 /*************************************************************/
 506 //** sub_FF878098_my @ 0xFF878098 - 0xFF8780D4, length=16
 507 void __attribute__((naked,noinline)) sub_FF878098_my() {
 508 asm volatile (
 509 "    STMFD   SP!, {R4,LR} \n"
 510 "    BL      sub_FF859C00_my \n"  // --> Patched. Old value = 0xFF859C00.
 511 //"  BL      _sub_FF91F284 \n"  // --> Nullsub call removed.
 512 "    LDR     R4, =0x585C \n"
 513 "    LDR     R0, [R4, #4] \n"
 514 "    CMP     R0, #0 \n"
 515 "    BNE     loc_FF8780CC \n"
 516 "    BL      sub_FF8590C8 \n"
 517 "    BL      sub_FF912FC0 \n"
 518 "    BL      sub_FF8590C8 \n"
 519 "    BL      sub_FF854F9C \n"
 520 "    BL      sub_FF858FC8 \n"
 521 "    BL      sub_FF91308C \n"
 522 
 523 "loc_FF8780CC:\n"
 524 "    MOV     R0, #1 \n"
 525 "    STR     R0, [R4] \n"
 526 "    LDMFD   SP!, {R4,PC} \n"
 527 );
 528 }
 529 
 530 /*************************************************************/
 531 //** sub_FF859C00_my @ 0xFF859C00 - 0xFF859C98, length=39
 532 void __attribute__((naked,noinline)) sub_FF859C00_my() {
 533 asm volatile (
 534 "    STMFD   SP!, {R4-R6,LR} \n"
 535 "    MOV     R6, #0 \n"
 536 "    MOV     R0, R6 \n"
 537 "    BL      sub_FF8596C0 \n"
 538 "    LDR     R4, =0x1A578 \n"
 539 "    MOV     R5, #0 \n"
 540 "    LDR     R0, [R4, #0x38] \n"
 541 "    BL      sub_FF85A120 \n"
 542 "    CMP     R0, #0 \n"
 543 "    LDREQ   R0, =0x2A5C \n"
 544 "    STREQ   R5, [R0, #0x10] \n"
 545 "    STREQ   R5, [R0, #0x14] \n"
 546 "    STREQ   R5, [R0, #0x18] \n"
 547 "    MOV     R0, R6 \n"
 548 "    BL      sub_FF859700 \n"
 549 "    MOV     R0, R6 \n"
 550 "    BL      sub_FF859A3C_my \n"  // --> Patched. Old value = 0xFF859A3C.
 551 "    MOV     R5, R0 \n"
 552 "    MOV     R0, R6 \n"
 553 "    BL      sub_FF859AA8 \n"
 554 "    LDR     R1, [R4, #0x3C] \n"
 555 "    AND     R2, R5, R0 \n"
 556 "    CMP     R1, #0 \n"
 557 "    MOV     R0, #0 \n"
 558 "    MOVEQ   R0, #0x80000001 \n"
 559 "    BEQ     loc_FF859C94 \n"
 560 "    LDR     R3, [R4, #0x2C] \n"
 561 "    CMP     R3, #2 \n"
 562 "    MOVEQ   R0, #4 \n"
 563 "    CMP     R1, #5 \n"
 564 "    ORRNE   R0, R0, #1 \n"
 565 "    BICEQ   R0, R0, #1 \n"
 566 "    CMP     R2, #0 \n"
 567 "    BICEQ   R0, R0, #2 \n"
 568 "    ORREQ   R0, R0, #0x80000000 \n"
 569 "    BICNE   R0, R0, #0x80000000 \n"
 570 "    ORRNE   R0, R0, #2 \n"
 571 
 572 "loc_FF859C94:\n"
 573 "    STR     R0, [R4, #0x40] \n"
 574 "    LDMFD   SP!, {R4-R6,PC} \n"
 575 );
 576 }
 577 
 578 /*************************************************************/
 579 //** sub_FF859A3C_my @ 0xFF859A3C - 0xFF859AA4, length=27
 580 void __attribute__((naked,noinline)) sub_FF859A3C_my() {
 581 asm volatile (
 582 "    STMFD   SP!, {R4-R6,LR} \n"
 583 "    LDR     R5, =0x2A5C \n"
 584 "    MOV     R6, R0 \n"
 585 "    LDR     R0, [R5, #0x14] \n"
 586 "    CMP     R0, #0 \n"
 587 "    MOVNE   R0, #1 \n"
 588 "    LDMNEFD SP!, {R4-R6,PC} \n"
 589 "    MOV     R0, #0x17 \n"
 590 "    MUL     R1, R0, R6 \n"
 591 "    LDR     R0, =0x1A578 \n"
 592 "    ADD     R4, R0, R1, LSL#2 \n"
 593 "    LDR     R0, [R4, #0x38] \n"
 594 "    MOV     R1, R6 \n"
 595 "    BL      sub_FF8597CC_my \n"  // --> Patched. Old value = 0xFF8597CC.
 596 "    CMP     R0, #0 \n"
 597 "    LDMEQFD SP!, {R4-R6,PC} \n"
 598 "    LDR     R0, [R4, #0x38] \n"
 599 "    MOV     R1, R6 \n"
 600 "    BL      sub_FF859934 \n"
 601 "    CMP     R0, #0 \n"
 602 "    LDMEQFD SP!, {R4-R6,PC} \n"
 603 "    MOV     R0, R6 \n"
 604 "    BL      sub_FF8592C8 \n"
 605 "    CMP     R0, #0 \n"
 606 "    MOVNE   R1, #1 \n"
 607 "    STRNE   R1, [R5, #0x14] \n"
 608 "    LDMFD   SP!, {R4-R6,PC} \n"
 609 );
 610 }
 611 
 612 /*************************************************************/
 613 //** sub_FF8597CC_my @ 0xFF8597CC - 0xFF859930, length=90
 614 void __attribute__((naked,noinline)) sub_FF8597CC_my() {
 615 asm volatile (
 616 "    STMFD   SP!, {R4-R8,LR} \n"
 617 "    MOV     R8, R0 \n"
 618 "    MOV     R0, #0x17 \n"
 619 "    MUL     R1, R0, R1 \n"
 620 "    LDR     R0, =0x1A578 \n"
 621 "    MOV     R6, #0 \n"
 622 "    ADD     R7, R0, R1, LSL#2 \n"
 623 "    LDR     R0, [R7, #0x3C] \n"
 624 "    MOV     R5, #0 \n"
 625 "    CMP     R0, #6 \n"
 626 "    ADDLS   PC, PC, R0, LSL#2 \n"
 627 "    B       loc_FF859918 \n"
 628 "    B       loc_FF859830 \n"
 629 "    B       loc_FF859818 \n"
 630 "    B       loc_FF859818 \n"
 631 "    B       loc_FF859818 \n"
 632 "    B       loc_FF859818 \n"
 633 "    B       loc_FF859910 \n"
 634 "    B       loc_FF859818 \n"
 635 
 636 "loc_FF859818:\n"
 637 "    MOV     R2, #0 \n"
 638 "    MOV     R1, #0x200 \n"
 639 "    MOV     R0, #2 \n"
 640 "    BL      sub_FF872014 \n"
 641 "    MOVS    R4, R0 \n"
 642 "    BNE     loc_FF859838 \n"
 643 
 644 "loc_FF859830:\n"
 645 "    MOV     R0, #0 \n"
 646 "    LDMFD   SP!, {R4-R8,PC} \n"
 647 
 648 "loc_FF859838:\n"
 649 "    LDR     R12, [R7, #0x4C] \n"
 650 "    MOV     R3, R4 \n"
 651 "    MOV     R2, #1 \n"
 652 "    MOV     R1, #0 \n"
 653 "    MOV     R0, R8 \n"
 654 "    BLX     R12 \n"
 655 "    CMP     R0, #1 \n"
 656 "    BNE     loc_FF859864 \n"
 657 "    MOV     R0, #2 \n"
 658 "    BL      sub_FF872160 \n"
 659 "    B       loc_FF859830 \n"
 660 
 661 "loc_FF859864:\n"
 662 "    MOV     R0, R8 \n"
 663 "    BL      sub_FF92AC04 \n"
 664 
 665 "    MOV     R1, R4\n"              //  pointer to MBR in R1
 666 "    BL      mbr_read_dryos\n"      //  total sectors count in R0 before and after call
 667 
 668 // Start of DataGhost's FAT32 autodetection code
 669 // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage
 670 // According to the code below, we can use R1, R2, R3 and R12.
 671 // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing
 672 // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :)
 673 "    MOV     R12, R4\n"             // Copy the MBR start address so we have something to work with
 674 "    MOV     LR, R4\n"              // Save old offset for MBR signature
 675 "    MOV     R1, #1\n"              // Note the current partition number
 676 "    B       dg_sd_fat32_enter\n"   // We actually need to check the first partition as well, no increments yet!
 677 "dg_sd_fat32:\n"
 678 "    CMP     R1, #4\n"              // Did we already see the 4th partition?
 679 "    BEQ     dg_sd_fat32_end\n"     // Yes, break. We didn't find anything, so don't change anything.
 680 "    ADD     R12, R12, #0x10\n"     // Second partition
 681 "    ADD     R1, R1, #1\n"          // Second partition for the loop
 682 "dg_sd_fat32_enter:\n"
 683 "    LDRB    R2, [R12, #0x1BE]\n"   // Partition status
 684 "    LDRB    R3, [R12, #0x1C2]\n"   // Partition type (FAT32 = 0xB)
 685 "    CMP     R3, #0xB\n"            // Is this a FAT32 partition?
 686 "    CMPNE   R3, #0xC\n"            // Not 0xB, is it 0xC (FAT32 LBA) then?
 687 "    BNE     dg_sd_fat32\n"         // No, it isn't. Loop again.
 688 "    CMP     R2, #0x00\n"           // It is, check the validity of the partition type
 689 "    CMPNE   R2, #0x80\n"
 690 "    BNE     dg_sd_fat32\n"         // Invalid, go to next partition
 691                                     // This partition is valid, it's the first one, bingo!
 692 "    MOV     R4, R12\n"             // Move the new MBR offset for the partition detection.
 693 
 694 "dg_sd_fat32_end:\n"
 695 // End of DataGhost's FAT32 autodetection code
 696 
 697 "    LDRB    R1, [R4, #0x1C9] \n"
 698 "    LDRB    R3, [R4, #0x1C8] \n"
 699 "    LDRB    R12, [R4, #0x1CC] \n"
 700 "    MOV     R1, R1, LSL#24 \n"
 701 "    ORR     R1, R1, R3, LSL#16 \n"
 702 "    LDRB    R3, [R4, #0x1C7] \n"
 703 "    LDRB    R2, [R4, #0x1BE] \n"
 704 //"  LDRB    LR, [R4, #0x1FF] \n"  // replaced below
 705 "    ORR     R1, R1, R3, LSL#8 \n"
 706 "    LDRB    R3, [R4, #0x1C6] \n"
 707 "    CMP     R2, #0 \n"
 708 "    CMPNE   R2, #0x80 \n"
 709 "    ORR     R1, R1, R3 \n"
 710 "    LDRB    R3, [R4, #0x1CD] \n"
 711 "    MOV     R3, R3, LSL#24 \n"
 712 "    ORR     R3, R3, R12, LSL#16 \n"
 713 "    LDRB    R12, [R4, #0x1CB] \n"
 714 "    ORR     R3, R3, R12, LSL#8 \n"
 715 "    LDRB    R12, [R4, #0x1CA] \n"
 716 "    ORR     R3, R3, R12 \n"
 717 //"  LDRB    R12, [R4, #0x1FE] \n"  // replaced below
 718 "    LDRB    R12, [LR,#0x1FE]\n"    // replace instructions above
 719 "    LDRB    LR, [LR,#0x1FF]\n"     // replace instructions above
 720 "    MOV     R4, #0 \n"
 721 "    BNE     loc_FF8598EC \n"
 722 "    CMP     R0, R1 \n"
 723 "    BCC     loc_FF8598EC \n"
 724 "    ADD     R2, R1, R3 \n"
 725 "    CMP     R2, R0 \n"
 726 "    CMPLS   R12, #0x55 \n"
 727 "    CMPEQ   LR, #0xAA \n"
 728 "    MOVEQ   R6, R1 \n"
 729 "    MOVEQ   R5, R3 \n"
 730 "    MOVEQ   R4, #1 \n"
 731 
 732 "loc_FF8598EC:\n"
 733 "    MOV     R0, #2 \n"
 734 "    BL      sub_FF872160 \n"
 735 "    CMP     R4, #0 \n"
 736 "    BNE     loc_FF859924 \n"
 737 "    MOV     R6, #0 \n"
 738 "    MOV     R0, R8 \n"
 739 "    BL      sub_FF92AC04 \n"
 740 "    MOV     R5, R0 \n"
 741 "    B       loc_FF859924 \n"
 742 
 743 "loc_FF859910:\n"
 744 "    MOV     R5, #0x40 \n"
 745 "    B       loc_FF859924 \n"
 746 
 747 "loc_FF859918:\n"
 748 "    LDR     R1, =0x37A \n"
 749 "    LDR     R0, =0xFF8597C0 /*'Mounter.c'*/ \n"
 750 "    BL      _DebugAssert \n"
 751 
 752 "loc_FF859924:\n"
 753 "    STR     R6, [R7, #0x44]! \n"
 754 "    MOV     R0, #1 \n"
 755 "    STR     R5, [R7, #4] \n"
 756 "    LDMFD   SP!, {R4-R8,PC} \n"
 757 );
 758 }
 759 
 760 /*************************************************************/
 761 //** JogDial_task_my @ 0xFF84B23C - 0xFF84B334, length=63
 762 void __attribute__((naked,noinline)) JogDial_task_my() {
 763 asm volatile (
 764 "    STMFD   SP!, {R3-R11,LR} \n"
 765 "    BL      sub_FF84B3EC \n"
 766 "    LDR     R11, =0x80000B01 \n"
 767 "    LDR     R8, =0xFFB0FA70 \n"
 768 "    LDR     R7, =0xC0240000 \n"
 769 "    LDR     R6, =0x25F0 \n"
 770 "    MOV     R9, #1 \n"
 771 "    MOV     R10, #0 \n"
 772 
 773 "loc_FF84B25C:\n"
 774 "    LDR     R3, =0x1AE \n"
 775 "    LDR     R0, [R6, #0xC] \n"
 776 "    LDR     R2, =0xFF84B494 /*'JogDial.c'*/ \n"
 777 "    MOV     R1, #0 \n"
 778 "    BL      sub_FF82862C /*_TakeSemaphoreStrictly*/ \n"
 779 "    MOV     R0, #0x28 \n"
 780 "    BL      _SleepTask \n"
 781 //------------------  added code ---------------------
 782 "sleep_loop:\n"
 783 "    LDR     R0, =jogdial_stopped\n"
 784 "    LDR     R0, [R0]\n"
 785 "    CMP     R0, #1\n"
 786 "    BNE     sleep_done\n"
 787 "    MOV     R0, #40\n"
 788 "    BL      _SleepTask\n"
 789 "    B       sleep_loop\n"
 790 "sleep_done:\n"
 791 //------------------  original code ------------------
 792 "    LDR     R0, [R7, #0x104] \n"
 793 "    MOV     R0, R0, ASR#16 \n"
 794 "    STRH    R0, [R6] \n"
 795 "    LDRSH   R2, [R6, #2] \n"
 796 "    SUB     R1, R0, R2 \n"
 797 "    CMP     R1, #0 \n"
 798 "    BEQ     loc_FF84B320 \n"
 799 "    MOV     R5, R1 \n"
 800 "    RSBLT   R5, R5, #0 \n"
 801 "    MOVLE   R4, #0 \n"
 802 "    MOVGT   R4, #1 \n"
 803 "    CMP     R5, #0xFF \n"
 804 "    BLS     loc_FF84B2D4 \n"
 805 "    CMP     R1, #0 \n"
 806 "    RSBLE   R1, R2, #0xFF \n"
 807 "    ADDLE   R1, R1, #0x7F00 \n"
 808 "    ADDLE   R0, R1, R0 \n"
 809 "    RSBGT   R0, R0, #0xFF \n"
 810 "    ADDGT   R0, R0, #0x7F00 \n"
 811 "    ADDGT   R0, R0, R2 \n"
 812 "    ADD     R5, R0, #0x8000 \n"
 813 "    ADD     R5, R5, #1 \n"
 814 "    EOR     R4, R4, #1 \n"
 815 
 816 "loc_FF84B2D4:\n"
 817 "    LDR     R0, [R6, #0x14] \n"
 818 "    CMP     R0, #0 \n"
 819 "    BEQ     loc_FF84B318 \n"
 820 "    LDR     R0, [R6, #0x1C] \n"
 821 "    CMP     R0, #0 \n"
 822 "    BEQ     loc_FF84B300 \n"
 823 "    LDR     R1, [R8, R4, LSL#2] \n"
 824 "    CMP     R1, R0 \n"
 825 "    BEQ     loc_FF84B308 \n"
 826 "    LDR     R0, =0xB01 \n"
 827 "    BL      sub_FF87EC00 \n"
 828 
 829 "loc_FF84B300:\n"
 830 "    MOV     R0, R11 \n"
 831 "    BL      sub_FF87EC00 \n"
 832 
 833 "loc_FF84B308:\n"
 834 "    LDR     R0, [R8, R4, LSL#2] \n"
 835 "    MOV     R1, R5 \n"
 836 "    STR     R0, [R6, #0x1C] \n"
 837 "    BL      sub_FF87EB30 \n"
 838 
 839 "loc_FF84B318:\n"
 840 "    LDRH    R0, [R6] \n"
 841 "    STRH    R0, [R6, #2] \n"
 842 
 843 "loc_FF84B320:\n"
 844 "    STR     R10, [R7, #0x100] \n"
 845 "    STR     R9, [R7, #0x108] \n"
 846 "    LDR     R0, [R6, #0x10] \n"
 847 "    CMP     R0, #0 \n"
 848 "    BLNE    _SleepTask \n"
 849 "    B       loc_FF84B25C \n"
 850 );
 851 }

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