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

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