root/platform/sx530hs/sub/100a/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. spytask
  2. CreateTask_spytask
  3. debug_blink
  4. my_blinker
  5. boot
  6. CreateTask_my
  7. sub_FF0203C4_my
  8. sub_FF0228D4_my
  9. sub_FF024704_my
  10. sub_FF027A44_my
  11. sub_FF02BBC0_my
  12. task_Startup_my
  13. taskcreatePhySw_my
  14. fix_writable_media_flag
  15. init_file_modules_task
  16. JogDial_task_my
  17. init_required_fw_features

   1 /*
   2  * boot.c - auto-generated by CHDK code_gen.
   3  */
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 #include "core.h"
   7 #include "dryos31.h"
   8 
   9 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
  10 
  11 const char * const new_sa = &_end;
  12 
  13 extern void task_CaptSeq();
  14 extern void task_InitFileModules();
  15 extern void task_RotaryEncoder();
  16 //extern void task_MovieRecord();
  17 extern void task_ExpDrv();
  18 //extern void task_FileWrite();
  19 
  20 /*----------------------------------------------------------------------
  21         spytask
  22 -----------------------------------------------------------------------*/
  23 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  24 {
  25     (void)ua; (void)ub; (void)uc; (void)ud; (void)ue; (void)uf;
  26         core_spytask();
  27 }
  28 
  29 /*----------------------------------------------------------------------
  30         CreateTask_spytask
  31 -----------------------------------------------------------------------*/
  32 void CreateTask_spytask()
  33 {
  34         _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
  35 }
  36 
  37 ///*----------------------------------------------------------------------
  38 // Pointer to stack location where jogdial task records previous and current
  39 // jogdial positions
  40 short *jog_position;
  41 
  42 #define GREEN_LED       0xC022D1FC
  43 #define AF_LED          0xC022D034
  44 //debug use only
  45 
  46 int debug_blink(int save_R0) {
  47         int i;
  48         *((volatile int *) GREEN_LED) = 0x93d800; // Turn on LED
  49         for (i=0; i<800000; i++) // Wait a while
  50                 {
  51                 asm volatile ( "nop\n" );
  52                 }
  53 
  54         *((volatile int *) GREEN_LED) = 0x83dc00; // Turn off LED
  55         for (i=0; i<800000; i++) // Wait a while
  56                 {
  57                 asm volatile ( "nop\n" );
  58                 }
  59         return save_R0;
  60 };
  61 
  62 void __attribute__((naked,noinline)) my_blinker(int n) {
  63         asm volatile (
  64       "            STMFD   SP!, {R0-R9,LR}\n"
  65 );
  66         int i, j;
  67         for (j=0; j<n; j++)
  68         {
  69                 *((volatile int *) GREEN_LED) = 0x93d800; // Turn on LED
  70                 for (i=0; i<0x200000; i++) { asm volatile ( "nop \n" ); }
  71 
  72                 *((volatile int *) GREEN_LED) = 0x83dc00; // Turn off LED
  73                 for (i=0; i<0x400000; i++) { asm volatile ( "nop \n" ); }
  74         }
  75         for (i=0; i<0x900000; i++) { asm volatile ( "nop \n" ); }
  76         asm volatile (
  77       "            LDMFD   SP!, {R0-R9,PC}\n"
  78         );
  79 }
  80 
  81 /*----------------------------------------------------------------------
  82         boot()
  83 
  84         Main entry point for the CHDK code
  85 -----------------------------------------------------------------------*/
  86 
  87 /*************************************************************/
  88 //** boot @ 0xFF02000C - 0xFF02017C, length=93
  89 void __attribute__((naked,noinline)) boot() {
  90 asm volatile (
  91 "    LDR     R1, =0xC0410000 \n"
  92 "    MOV     R0, #0 \n"
  93 "    STR     R0, [R1] \n"
  94 "    MOV     R1, #0x78 \n"
  95 "    MCR     p15, 0, R1, c1, c0 \n"
  96 "    MOV     R1, #0 \n"
  97 "    MCR     p15, 0, R1, c7, c10, 4 \n"
  98 "    MCR     p15, 0, R1, c7, c5 \n"
  99 "    MCR     p15, 0, R1, c7, c6 \n"
 100 "    MOV     R0, #0x3D \n"
 101 "    MCR     p15, 0, R0, c6, c0 \n"
 102 "    MOV     R0, #0xC000002F \n"
 103 "    MCR     p15, 0, R0, c6, c1 \n"
 104 "    MOV     R0, #0x37 \n"
 105 "    MCR     p15, 0, R0, c6, c2 \n"
 106 "    MOV     R0, #0x40000037 \n"
 107 "    MCR     p15, 0, R0, c6, c3 \n"
 108 "    MOV     R0, #0x80000017 \n"
 109 "    MCR     p15, 0, R0, c6, c4 \n"
 110 "    LDR     R0, =0xFF00002F \n"
 111 "    MCR     p15, 0, R0, c6, c5 \n"
 112 "    MOV     R0, #0x34 \n"
 113 "    MCR     p15, 0, R0, c2, c0 \n"
 114 "    MOV     R0, #0x34 \n"
 115 "    MCR     p15, 0, R0, c2, c0, 1 \n"
 116 "    MOV     R0, #0x34 \n"
 117 "    MCR     p15, 0, R0, c3, c0 \n"
 118 "    LDR     R0, =0x3333330 \n"
 119 "    MCR     p15, 0, R0, c5, c0, 2 \n"
 120 "    LDR     R0, =0x3333330 \n"
 121 "    MCR     p15, 0, R0, c5, c0, 3 \n"
 122 "    MRC     p15, 0, R0, c1, c0 \n"
 123 "    ORR     R0, R0, #0x1000 \n"
 124 "    ORR     R0, R0, #4 \n"
 125 "    ORR     R0, R0, #1 \n"
 126 "    MCR     p15, 0, R0, c1, c0 \n"
 127 "    MOV     R1, #0x80000006 \n"
 128 "    MCR     p15, 0, R1, c9, c1 \n"
 129 "    MOV     R1, #6 \n"
 130 "    MCR     p15, 0, R1, c9, c1, 1 \n"
 131 "    MRC     p15, 0, R1, c1, c0 \n"
 132 "    ORR     R1, R1, #0x50000 \n"
 133 "    MCR     p15, 0, R1, c1, c0 \n"
 134 "    LDR     R2, =0xC0200000 \n"
 135 "    MOV     R1, #1 \n"
 136 "    STR     R1, [R2, #0x10C] \n"
 137 "    MVN     R1, #0 \n"
 138 "    STR     R1, [R2, #0xC] \n"
 139 "    STR     R1, [R2, #0x1C] \n"
 140 "    STR     R1, [R2, #0x2C] \n"
 141 "    STR     R1, [R2, #0x3C] \n"
 142 "    STR     R1, [R2, #0x4C] \n"
 143 "    STR     R1, [R2, #0x5C] \n"
 144 "    STR     R1, [R2, #0x6C] \n"
 145 "    STR     R1, [R2, #0x7C] \n"
 146 "    STR     R1, [R2, #0x8C] \n"
 147 "    STR     R1, [R2, #0x9C] \n"
 148 "    STR     R1, [R2, #0xAC] \n"
 149 "    STR     R1, [R2, #0xBC] \n"
 150 "    STR     R1, [R2, #0xCC] \n"
 151 "    STR     R1, [R2, #0xDC] \n"
 152 "    STR     R1, [R2, #0xEC] \n"
 153 "    STR     R1, [R2, #0xFC] \n"
 154 "    LDR     R1, =0xC0400008 \n"
 155 "    LDR     R2, =0x430005 \n"
 156 "    STR     R2, [R1] \n"
 157 "    MOV     R1, #1 \n"
 158 "    LDR     R2, =0xC0243100 \n"
 159 "    STR     R2, [R1] \n"
 160 "    LDR     R2, =0xC0242010 \n"
 161 "    LDR     R1, [R2] \n"
 162 "    ORR     R1, R1, #1 \n"
 163 "    STR     R1, [R2] \n"
 164 "    LDR     R0, =0xFF8C92A8 \n"
 165 "    LDR     R1, =0x6B1000 \n"
 166 "    LDR     R3, =0x6E28C6 \n"
 167 
 168 "loc_FF02013C:\n"
 169 "    CMP     R1, R3 \n"
 170 "    LDRCC   R2, [R0], #4 \n"
 171 "    STRCC   R2, [R1], #4 \n"
 172 "    BCC     loc_FF02013C \n"
 173 "    LDR     R0, =0xFF8B1318 \n"
 174 "    LDR     R1, =0x1900 \n"
 175 "    LDR     R3, =0x19890 \n"
 176 
 177 "loc_FF020158:\n"
 178 "    CMP     R1, R3 \n"
 179 "    LDRCC   R2, [R0], #4 \n"
 180 "    STRCC   R2, [R1], #4 \n"
 181 "    BCC     loc_FF020158 \n"
 182 "    LDR     R1, =0x2FF248 \n"
 183 "    MOV     R2, #0 \n"
 184 
 185 "loc_FF020170:\n"
 186 "    CMP     R3, R1 \n"
 187 "    STRCC   R2, [R3], #4 \n"
 188 "    BCC     loc_FF020170 \n"
 189 /* Install task hooks via 0x193x is not possible with this new dryos version
 190    So the below code patches the CreateTask function in RAM to install our
 191    hook -- ERR99
 192 */
 193 // Install CreateTask patch
 194 "    LDR     R0, =patch_CreateTask\n"   // Patch data
 195 "    LDM     R0, {R1,R2}\n"             // Get two patch instructions
 196 "    LDR     R0, =hook_CreateTask\n"    // Address to patch
 197 "    STM     R0, {R1,R2}\n"             // Store patch instructions
 198 
 199 "    B       sub_FF0203C4_my \n"  // --> Patched. Old value = 0xFF0203C4.
 200 
 201 "patch_CreateTask:\n"
 202 "    LDR     PC, [PC,#-0x4]\n"          // Do jump to absolute address CreateTask_my
 203 "    .long   CreateTask_my\n"
 204 );
 205 }
 206 
 207 /*************************************************************/
 208 //** CreateTask_my @ 0x006B5658 - 0x006B565C, length=2
 209 void __attribute__((naked,noinline)) CreateTask_my() {
 210 asm volatile (
 211 "    STMFD   SP!, {R0}\n"
 212 //R3 = Pointer to task function to create
 213 
 214 /*** INSTALL capt_seq_task() hook ***/
 215 "    LDR     R0, =task_CaptSeq\n"       // DryOS original code function ptr.
 216 "    CMP     R0, R3\n"                  // is the given taskptr equal to our searched function?
 217 "    LDREQ   R3, =capt_seq_task\n"      // if so replace with our task function base ptr.
 218 "    BEQ     exitHook\n"                // below compares not necessary if this check has found something.
 219 
 220 /*** INSTALL exp_drv_task() hook ***/
 221 "    LDR     R0, =task_ExpDrv\n"
 222 "    CMP     R0, R3\n"
 223 "    LDREQ   R3, =exp_drv_task\n"
 224 "    BEQ     exitHook\n"
 225 
 226 
 227 /*** INSTALL filewrite() hook ***/
 228 //"    LDR     R0, =task_FileWrite\n"
 229 //"    CMP     R0, R3\n"
 230 //"    LDREQ   R3, =filewritetask\n"
 231 //"    BEQ     exitHook\n"
 232 
 233 /*** INSTALL JogDial() hook ***/
 234 // was commented out in boot.c from http://chdk.setepontos.com/index.php?topic=12418.msg123489#msg123489
 235 // but not in codegen file - reyalp
 236 //"    LDR     R0, =task_RotaryEncoder\n"
 237 //"    CMP     R0, R3\n"
 238 //"    LDREQ   R3, =JogDial_task_my\n"
 239 //"    BEQ     exitHook\n"
 240 
 241 /*** INSTALL movie_record_task() hook ***/
 242 "    LDR     R0, =task_MovieRecord\n"
 243 "    CMP     R0, R3\n"
 244 "    LDREQ   R3, =movie_record_task\n"
 245 "    BEQ     exitHook\n"
 246 
 247 /*** INSTALL liveimage_task() hook ***/
 248 "    LDR     R0, =task_LiveImageTask\n"
 249 "    CMP     R0, R3\n"
 250 "    LDREQ   R3, =liveimage_task\n"
 251 "    BEQ     exitHook\n"
 252 
 253 /*** INSTALL init_file_modules_task() hook ***/
 254 "    LDR     R0, =task_InitFileModules\n"
 255 "    CMP     R0, R3\n"
 256 "    LDREQ   R3, =init_file_modules_task\n"
 257 
 258 "exitHook:\n" 
 259 // restore overwritten registers
 260 "    LDMFD   SP!, {R0}\n"
 261 // Execute overwritten instructions from original code, then jump to firmware
 262 "    STMFD   SP!, {R1-R9,LR} \n"
 263 "    MOV     R4, R0 \n"
 264 "    LDR     PC, =0x006B5660 \n"  // Continue in firmware
 265 );
 266 }
 267 
 268 /*************************************************************/
 269 //** sub_FF0203C4_my @ 0xFF0203C4 - 0xFF020434, length=29
 270 void __attribute__((naked,noinline)) sub_FF0203C4_my() {
 271 
 272     //Replacement of sub_ for correct power-on.
 273     //(short press on ON/OFF button = playback mode, long press = record mode)
 274     // see sub_ff02bbc0 and sub_ff073c68 (100c)
 275     // NOTE this might break other startup modes (such as NFC)
 276     *(int*)(0x2cf4+0x8) = (*(int*)0xc022f48c) & 0x80000 ? 0x400000 : 0x200000;
 277 
 278 asm volatile (
 279 "    LDR     R0, =0xFF02043C \n"
 280 "    MOV     R1, #0 \n"
 281 "    LDR     R3, =0xFF020474 \n"
 282 
 283 "loc_FF0203D0:\n"
 284 "    CMP     R0, R3 \n"
 285 "    LDRCC   R2, [R0], #4 \n"
 286 "    STRCC   R2, [R1], #4 \n"
 287 "    BCC     loc_FF0203D0 \n"
 288 "    LDR     R0, =0xFF020474 \n"
 289 "    MOV     R1, #0x1C0 \n"
 290 "    LDR     R3, =0xFF02065C \n"
 291 
 292 "loc_FF0203EC:\n"
 293 "    CMP     R0, R3 \n"
 294 "    LDRCC   R2, [R0], #4 \n"
 295 "    STRCC   R2, [R1], #4 \n"
 296 "    BCC     loc_FF0203EC \n"
 297 "    MOV     R0, #0xD2 \n"
 298 "    MSR     CPSR_cxsf, R0 \n"
 299 "    MOV     SP, #0x1000 \n"
 300 "    MOV     R0, #0xD3 \n"
 301 "    MSR     CPSR_cxsf, R0 \n"
 302 "    MOV     SP, #0x1000 \n"
 303 "    LDR     R0, =0x3A8 \n"
 304 "    LDR     R2, =0xEEEEEEEE \n"
 305 "    MOV     R3, #0x1000 \n"
 306 
 307 "loc_FF020420:\n"
 308 "    CMP     R0, R3 \n"
 309 "    STRCC   R2, [R0], #4 \n"
 310 "    BCC     loc_FF020420 \n"
 311 "    B       sub_FF0228D4_my \n"  // --> Patched. Old value = 0xFF0228D4.
 312 );
 313 }
 314 
 315 /*************************************************************/
 316 //** sub_FF0228D4_my @ 0xFF0228D4 - 0xFF0229E0, length=68
 317 void __attribute__((naked,noinline)) sub_FF0228D4_my() {
 318 asm volatile (
 319 "    LDR     R1, =0x1A5C \n"
 320 "    STR     LR, [SP, #-4]! \n"
 321 "    SUB     SP, SP, #0x7C \n"
 322 "    MOV     R0, #0x80000 \n"
 323 "    STR     R0, [R1] \n"
 324 "    LDR     R0, =0x40D42F80 \n"
 325 "    LDR     R1, =0x1A60 \n"
 326 "    STR     R0, [R1] \n"
 327 "    LDR     R1, =0x1A64 \n"
 328 "    ADD     R0, R0, #0x2000 \n"
 329 "    STR     R0, [R1] \n"
 330 "    MOV     R1, #0x78 \n"
 331 "    ADD     R0, SP, #4 \n"
 332 "    BL      sub_006DABD4 \n"
 333 "    MOV     R0, #0xA0000 \n"
 334 "    STR     R0, [SP, #8] \n"
 335 
 336 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 337 "    LDR     R0, =0x2FF248 \n"
 338 #else
 339 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 340 "    LDR     R0, [R0]\n"      //
 341 #endif
 342 
 343 "    LDR     R2, =0x56346C \n"
 344 "    STR     R0, [SP, #0xC] \n"
 345 "    SUB     R0, R2, R0 \n"
 346 "    STR     R0, [SP, #0x10] \n"
 347 "    MOV     R0, #0x22 \n"
 348 "    STR     R0, [SP, #0x1C] \n"
 349 "    MOV     R0, #0x98 \n"
 350 "    STR     R0, [SP, #0x20] \n"
 351 "    MOV     R0, #0x1E8 \n"
 352 "    STR     R2, [SP, #0x14] \n"
 353 "    STR     R0, [SP, #0x24] \n"
 354 "    LDR     R1, =0x56E000 \n"
 355 "    MOV     R0, #0xFA \n"
 356 "    STR     R0, [SP, #0x28] \n"
 357 "    MOV     R0, #0xB6 \n"
 358 "    STR     R1, [SP, #4] \n"
 359 "    STR     R0, [SP, #0x2C] \n"
 360 "    MOV     R0, #0x85 \n"
 361 "    STR     R0, [SP, #0x30] \n"
 362 "    MOV     R0, #0x40 \n"
 363 "    STR     R0, [SP, #0x34] \n"
 364 "    MOV     R0, #4 \n"
 365 "    STR     R0, [SP, #0x38] \n"
 366 "    MOV     R0, #0 \n"
 367 "    STR     R0, [SP, #0x3C] \n"
 368 "    MOV     R0, #0x10 \n"
 369 "    STR     R0, [SP, #0x60] \n"
 370 "    MOV     R0, #0x1000 \n"
 371 "    STR     R0, [SP, #0x64] \n"
 372 "    MOV     R0, #0x100 \n"
 373 "    STR     R0, [SP, #0x68] \n"
 374 "    MOV     R0, #0x2000 \n"
 375 "    STR     R1, [SP, #0x18] \n"
 376 "    STR     R0, [SP, #0x6C] \n"
 377 "    LDR     R1, =sub_FF024704_my \n"  // --> Patched. Old value = 0xFF024704.
 378 "    MOV     R2, #0 \n"
 379 "    ADD     R0, SP, #4 \n"
 380 "    BL      sub_006B1BC8 \n"
 381 "    ADD     SP, SP, #0x7C \n"
 382 "    LDR     PC, [SP], #4 \n"
 383 );
 384 }
 385 
 386 /*************************************************************/
 387 //** sub_FF024704_my @ 0xFF024704 - 0xFF02479C, length=39
 388 void __attribute__((naked,noinline)) sub_FF024704_my() {
 389 asm volatile (
 390 "    STMFD   SP!, {R4,LR} \n"
 391 "    LDR     R4, =0xFF0247C0 /*'/_term'*/ \n"
 392 "    BL      sub_FF020858 \n"
 393 "    LDR     R1, =0x1A5C \n"
 394 "    LDR     R0, =0x19F0 \n"
 395 "    LDR     R1, [R1] \n"
 396 "    LDR     R0, [R0] \n"
 397 "    ADD     R1, R1, #0x10 \n"
 398 "    CMP     R0, R1 \n"
 399 "    LDRCC   R0, =0xFF0247D0 /*'USER_MEM size checking'*/ \n"
 400 "    BLCC    _err_init_task \n"
 401 "    BL      sub_FF0234E0 \n"
 402 "    CMP     R0, #0 \n"
 403 "    LDRLT   R0, =0xFF0247E8 /*'dmSetup'*/ \n"
 404 "    BLLT    _err_init_task \n"
 405 "    BL      sub_FF0224E8 \n"
 406 "    CMP     R0, #0 \n"
 407 "    LDRLT   R0, =0xFF0247F0 /*'termDriverInit'*/ \n"
 408 "    BLLT    _err_init_task \n"
 409 "    MOV     R0, R4 \n"
 410 "    BL      sub_FF0225C8 \n"
 411 "    CMP     R0, #0 \n"
 412 "    LDRLT   R0, =0xFF024800 /*'termDeviceCreate'*/ \n"
 413 "    BLLT    _err_init_task \n"
 414 "    MOV     R0, R4 \n"
 415 "    BL      sub_FF022100 \n"
 416 "    CMP     R0, #0 \n"
 417 "    LDRLT   R0, =0xFF024814 /*'stdioSetup'*/ \n"
 418 "    BLLT    _err_init_task \n"
 419 "    BL      sub_FF024D70 \n"
 420 "    CMP     R0, #0 \n"
 421 "    LDRLT   R0, =0xFF024820 /*'stdlibSetup'*/ \n"
 422 "    BLLT    _err_init_task \n"
 423 "    BL      sub_FF0210A8 \n"
 424 "    CMP     R0, #0 \n"
 425 "    LDRLT   R0, =0xFF02482C /*'extlib_setup'*/ \n"
 426 "    BLLT    _err_init_task \n"
 427 "    LDMFD   SP!, {R4,LR} \n"
 428 "    B       sub_FF027A44_my \n"  // --> Patched. Old value = 0xFF027A44.
 429 );
 430 }
 431 
 432 /*************************************************************/
 433 //** sub_FF027A44_my @ 0xFF027A44 - 0xFF027AB4, length=29
 434 void __attribute__((naked,noinline)) sub_FF027A44_my() {
 435 asm volatile (
 436 "    STMFD   SP!, {R3,LR} \n"
 437 "    BL      sub_FF033F14 \n"
 438 "    BL      sub_FF037D3C \n"
 439 "    CMP     R0, #0 \n"
 440 "    BNE     loc_FF027A68 \n"
 441 "    BL      sub_FF02D16C /*_IsNormalCameraMode_FW*/ \n"
 442 "    CMP     R0, #0 \n"
 443 "    MOVNE   R0, #1 \n"
 444 "    BNE     loc_FF027A6C \n"
 445 
 446 "loc_FF027A68:\n"
 447 "    MOV     R0, #0 \n"
 448 
 449 "loc_FF027A6C:\n"
 450 "    BL      sub_FF02BBC0_my \n"  // --> Patched. Old value = 0xFF02BBC0.
 451 "    CMP     R0, #0 \n"
 452 "    BNE     loc_FF027A80 \n"
 453 "    BL      sub_FF02B3A4 \n"
 454 
 455 "loc_FF027A7C:\n"
 456 "    B       loc_FF027A7C \n"
 457 
 458 "loc_FF027A80:\n"
 459 "    BL      sub_006B8AD0 \n"
 460 "    LDR     R1, =0x60E000 \n"
 461 "    MOV     R0, #0 \n"
 462 "    BL      sub_FF03822C \n"
 463 "    BL      sub_006B8E18 /*_EnableDispatch*/ \n"
 464 "    MOV     R3, #0 \n"
 465 "    STR     R3, [SP] \n"
 466 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF0279DC.
 467 "    MOV     R2, #0 \n"
 468 "    MOV     R1, #0x19 \n"
 469 "    LDR     R0, =0xFF027AC0 /*'Startup'*/ \n"
 470 "    BL      _CreateTask \n"
 471 "    MOV     R0, #0 \n"
 472 "    LDMFD   SP!, {R3,PC} \n"
 473 );
 474 }
 475 
 476 /*************************************************************/
 477 //** sub_FF02BBC0_my @ 0xFF02BBC0 - 0xFF02BC6C, length=44
 478 void __attribute__((naked,noinline)) sub_FF02BBC0_my() {
 479 asm volatile (
 480 "    STMFD   SP!, {R2-R10,LR} \n"
 481 "    MOV     R4, #0 \n"
 482 "    MOV     R10, R0 \n"
 483 "    MOV     R5, R4 \n"
 484 "    MOV     R7, R4 \n"
 485 //"  BL      _sub_FF073C60 \n"  // --> Nullsub call removed.
 486 "    MOV     R0, #0x47 \n"
 487 "    BL      sub_FF071738 \n"
 488 "    MOV     R6, #1 \n"
 489 "    BIC     R8, R6, R0 \n"
 490 "    MOV     R0, #0x48 \n"
 491 "    BL      sub_FF071738 \n"
 492 "    BIC     R9, R6, R0 \n"
 493 "    MOV     R0, #0 \n"
 494 "    BL      sub_FF073C40 \n"
 495 "    CMP     R0, #0 \n"
 496 "    BEQ     loc_FF02BC10 \n"
 497 "    MOV     R0, #0x49 \n"
 498 "    BL      sub_FF071738 \n"
 499 "    BIC     R5, R6, R0 \n"
 500 
 501 "loc_FF02BC10:\n"
 502 "    MOV     R0, #1 \n"
 503 "    BL      sub_FF073C40 \n"
 504 "    CMP     R0, #0 \n"
 505 "    BEQ     loc_FF02BC2C \n"
 506 "    MOV     R0, #0x4E \n"
 507 "    BL      sub_FF071738 \n"
 508 "    BIC     R4, R6, R0 \n"
 509 
 510 "loc_FF02BC2C:\n"
 511 "    CMP     R10, #0 \n"
 512 "    BEQ     loc_FF02BC44 \n"
 513 "    ORR     R0, R8, R9 \n"
 514 "    ORR     R0, R0, R5 \n"
 515 "    ORRS    R0, R0, R4 \n"
 516 "    BEQ     loc_FF02BC6C \n"
 517 
 518 "loc_FF02BC44:\n"
 519 "    BL      sub_FF037D3C \n"
 520 "    MOV     R2, R0 \n"
 521 "    MOV     R3, R5 \n"
 522 "    MOV     R1, R9 \n"
 523 "    MOV     R0, R8 \n"
 524 "    STR     R4, [SP, #4] \n"
 525 "    STR     R7, [SP] \n"
 526 //"  BL      _sub_FF073C68 \n"  // Disable StartUpChecks
 527 //"  BL      _sub_FF073C64 \n"  // --> Nullsub call removed.
 528 "    MOV     R0, #1 \n"
 529 
 530 "loc_FF02BC6C:\n"
 531 "    LDMFD   SP!, {R2-R10,PC} \n"
 532 );
 533 }
 534 
 535 /*************************************************************/
 536 //** task_Startup_my @ 0xFF0279DC - 0xFF027A40, length=26
 537 void __attribute__((naked,noinline)) task_Startup_my() {
 538 asm volatile (
 539 "    STMFD   SP!, {R4,LR} \n"
 540 "    BL      sub_FF022C84 \n"
 541 "    BL      sub_FF02C090 \n"
 542 "    BL      sub_FF02B350 \n"
 543 //"  BL      _sub_FF074CE0 \n"  // --> Nullsub call removed.
 544 "    BL      sub_FF037F58 \n"
 545 //"  BL      _sub_FF037E18 \n"  // load DISKBOOT.BIN
 546 "    BL      sub_FF0380B8 \n"
 547 "    BL      sub_FF038300 \n"
 548 //"  BL      _sub_FF0380AC \n"  // --> Nullsub call removed.
 549 "    BL      sub_FF037F94 \n"
 550 "    BL      sub_FF033E4C \n"
 551 "    BL      sub_FF038308 \n"
 552 "    BL      CreateTask_spytask\n" // added
 553 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFF02BA68.
 554 "    BL      init_required_fw_features\n" // added
 555 "    BL      sub_FF0314D8 \n"
 556 "    BL      sub_FF0C74B4 \n"
 557 "    BL      sub_FF028E34 \n"
 558 "    BL      sub_FF02ACC8 \n"
 559 "    BL      sub_FF037B24 \n"
 560 "    BL      sub_FF02B304 \n"
 561 "    BL      sub_FF02AC5C \n"
 562 //"  BL      _sub_FF0380B0 \n"  // --> Nullsub call removed.
 563 "    BL      sub_FF029C10 \n"
 564 "    BL      sub_FF02AC18 \n"
 565 "    LDMFD   SP!, {R4,LR} \n"
 566 "    B       sub_FF022DD4 \n"
 567 );
 568 }
 569 
 570 /*************************************************************/
 571 //** taskcreatePhySw_my @ 0xFF02BA68 - 0xFF02BAB0, length=19
 572 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 573 asm volatile (
 574 "    STMFD   SP!, {R3-R5,LR} \n"
 575 "    BL      sub_FF036D84 \n"
 576 "    BL      sub_FF02D0A4 /*_IsFactoryMode_FW*/ \n"
 577 "    CMP     R0, #0 \n"
 578 "    BLEQ    sub_FF036CEC /*_OpLog.Start_FW*/ \n"
 579 "    LDR     R4, =0x1CA0 \n"
 580 "    LDR     R0, [R4, #4] \n"
 581 "    CMP     R0, #0 \n"
 582 "    BNE     loc_FF02BAAC \n"
 583 "    MOV     R3, #0 \n"
 584 "    STR     R3, [SP] \n"
 585 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF02BA34.
 586 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw so we don't have to do stack switch
 587 "    MOV     R1, #0x17 \n"
 588 "    LDR     R0, =0xFF02BC80 /*'PhySw'*/ \n"
 589 "    BL      sub_006B7BE0 /*_CreateTaskStrictly*/ \n"
 590 "    STR     R0, [R4, #4] \n"
 591 
 592 "loc_FF02BAAC:\n"
 593 "    LDMFD   SP!, {R3-R5,LR} \n"
 594 "    B       sub_FF074BC4 \n"
 595 );
 596 }
 597 
 598 // Workaround for cards becoming read-only in camera when diskboot'ing to playback mode.
 599 // The following flag is checked by the function that calls WriteSDCard (sub_ff0300dc)
 600 // See the porting thread for related discussions. https://chdk.setepontos.com/index.php?topic=12418
 601 void fix_writable_media_flag() {
 602     *(int*)0x1d60 = 1;
 603 }
 604 
 605 /*************************************************************/
 606 //** init_file_modules_task @ 0xFF061C70 - 0xFF061CA4, length=14
 607 void __attribute__((naked,noinline)) init_file_modules_task() {
 608 asm volatile (
 609 "    STMFD   SP!, {R4-R6,LR} \n"
 610 "    BL      sub_FF0B0B54 \n"
 611 "    LDR     R5, =0x5006 \n"
 612 "    MOVS    R4, R0 \n"
 613 "    MOVNE   R1, #0 \n"
 614 "    MOVNE   R0, R5 \n"
 615 "    BLNE    _PostLogicalEventToUI \n"
 616 "    BL      sub_FF0B0B84 \n"
 617 "    BL      fix_writable_media_flag\n" // port specific hack
 618 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 619 "    CMP     R4, #0 \n"
 620 "    LDMNEFD SP!, {R4-R6,PC} \n"
 621 "    MOV     R0, R5 \n"
 622 "    LDMFD   SP!, {R4-R6,LR} \n"
 623 "    MOV     R1, #0 \n"
 624 "    B       _PostLogicalEventToUI \n"
 625 );
 626 }
 627 
 628 /*************************************************************/
 629 //** JogDial_task_my @ 0xFF0748A0 - 0xFF074BC0, length=201
 630 void __attribute__((naked,noinline)) JogDial_task_my() {
 631 asm volatile (
 632 "    STMFD   SP!, {R4-R11,LR} \n"
 633 "    SUB     SP, SP, #0x24 \n"
 634 "    BL      sub_FF074C04 \n"
 635 "    LDR     R3, =0x2D20 \n"
 636 "    LDR     R6, =0xFF63F00C \n"
 637 "    MOV     R0, #0 \n"
 638 "    ADD     R11, SP, #0xC \n"
 639 "    ADD     R9, SP, #0x10 \n"
 640 
 641 // Save pointer for kbd.c routine
 642 "    LDR     R2, =jog_position \n"
 643 "    STR     R9, [R2] \n"
 644 
 645 "    MOV     R10, R0 \n"
 646 
 647 "loc_FF0748C4:\n"
 648 "    ADD     R1, SP, #0x18 \n"
 649 "    ADD     R12, R1, R0, LSL#1 \n"
 650 "    ADD     R2, SP, #0x14 \n"
 651 "    STRH    R10, [R12] \n"
 652 "    ADD     R12, R2, R0, LSL#1 \n"
 653 "    STRH    R10, [R12] \n"
 654 "    STR     R10, [R9, R0, LSL#2] \n"
 655 "    STR     R10, [R11, R0, LSL#2] \n"
 656 "    ADD     R0, R0, #1 \n"
 657 "    CMP     R0, #1 \n"
 658 "    BLT     loc_FF0748C4 \n"
 659 
 660 "loc_FF0748F0:\n"
 661 "    LDR     R0, =0x2D20 \n"
 662 "    MOV     R2, #0 \n"
 663 "    LDR     R0, [R0, #8] \n"
 664 "    ADD     R1, SP, #4 \n"
 665 "    BL      sub_006B849C /*_ReceiveMessageQueue*/ \n"
 666 "    CMP     R0, #0 \n"
 667 "    LDRNE   R2, =0x229 \n"
 668 "    LDRNE   R1, =0xFF074B6C /*'RotaryEncoder.c'*/ \n"
 669 "    MOVNE   R0, #0 \n"
 670 "    BLNE    _DebugAssert \n"
 671 "    LDR     R0, [SP, #4] \n"
 672 "    AND     R4, R0, #0xFF \n"
 673 "    AND     R0, R0, #0xFF00 \n"
 674 "    CMP     R0, #0x100 \n"
 675 "    BEQ     loc_FF074968 \n"
 676 "    CMP     R0, #0x200 \n"
 677 "    BEQ     loc_FF0749A0 \n"
 678 "    CMP     R0, #0x300 \n"
 679 "    BNE     loc_FF0748F0 \n"
 680 "    LDR     R0, [R9, R4, LSL#2] \n"
 681 "    CMP     R0, #0 \n"
 682 "    LDREQ   R2, =0x296 \n"
 683 "    LDREQ   R1, =0xFF074B6C /*'RotaryEncoder.c'*/ \n"
 684 "    BLEQ    _DebugAssert \n"
 685 "    RSB     R0, R4, R4, LSL#3 \n"
 686 "    ADD     R0, R6, R0, LSL#2 \n"
 687 "    LDR     R0, [R0, #0xC] \n"
 688 "    BL      sub_FF02BAB4 \n"
 689 "    STR     R10, [R9, R4, LSL#2] \n"
 690 "    B       loc_FF0748F0 \n"
 691 
 692 "loc_FF074968:\n"
 693 //------------------  added code ---------------------
 694 "labelA:\n"
 695 "    LDR     R0, =jogdial_stopped\n"
 696 "    LDR     R0, [R0]\n"
 697 "    CMP     R0, #1\n"
 698 "    BNE     labelB\n"
 699 "    MOV     R0, #40\n"
 700 "    BL      _SleepTask\n"
 701 "    B       labelA\n"
 702 "labelB:\n"
 703 //------------------  original code ------------------
 704 "    LDR     R0, =0x2D2C \n"
 705 "    LDR     R0, [R0, R4, LSL#2] \n"
 706 "    BL      sub_FF025FF0 /*_CancelTimer*/ \n"
 707 "    LDR     R2, =0xFF0747E4 \n"
 708 "    ORR     R3, R4, #0x200 \n"
 709 "    MOV     R1, R2 \n"
 710 "    MOV     R0, #0x28 \n"
 711 "    BL      sub_FF025F20 /*_SetTimerAfter*/ \n"
 712 "    TST     R0, #1 \n"
 713 "    CMPNE   R0, #0x15 \n"
 714 "    STR     R0, [R11, R4, LSL#2] \n"
 715 "    BEQ     loc_FF0748F0 \n"
 716 "    LDR     R2, =0x23B \n"
 717 "    B       loc_FF074B54 \n"
 718 
 719 "loc_FF0749A0:\n"
 720 "    RSB     R5, R4, R4, LSL#3 \n"
 721 "    LDR     R0, [R6, R5, LSL#2] \n"
 722 "    LDR     R1, =0xC0240000 \n"
 723 "    ADD     R0, R1, R0, LSL#8 \n"
 724 "    LDR     R0, [R0, #0x104] \n"
 725 "    MOV     R1, R0, ASR#16 \n"
 726 "    ADD     R0, SP, #0x18 \n"
 727 "    ADD     R0, R0, R4, LSL#1 \n"
 728 "    STR     R0, [SP, #0x20] \n"
 729 "    STRH    R1, [R0] \n"
 730 "    ADD     R0, SP, #0x14 \n"
 731 "    ADD     R0, R0, R4, LSL#1 \n"
 732 "    STR     R0, [SP, #0x1C] \n"
 733 "    LDRSH   R3, [R0] \n"
 734 "    SUB     R2, R1, R3 \n"
 735 "    CMP     R2, #0 \n"
 736 "    BNE     loc_FF074A28 \n"
 737 "    LDR     R0, [R9, R4, LSL#2] \n"
 738 "    CMP     R0, #0 \n"
 739 "    BEQ     loc_FF074B10 \n"
 740 "    LDR     R7, =0x2D2C \n"
 741 "    LDR     R0, [R7, R4, LSL#2] \n"
 742 "    BL      sub_FF025FF0 /*_CancelTimer*/ \n"
 743 "    LDR     R2, =0xFF0747F0 \n"
 744 "    ORR     R3, R4, #0x300 \n"
 745 "    MOV     R1, R2 \n"
 746 "    MOV     R0, #0x1F4 \n"
 747 "    BL      sub_FF025F20 /*_SetTimerAfter*/ \n"
 748 "    TST     R0, #1 \n"
 749 "    CMPNE   R0, #0x15 \n"
 750 "    STR     R0, [R7, R4, LSL#2] \n"
 751 "    BEQ     loc_FF074B10 \n"
 752 "    MOV     R2, #0x254 \n"
 753 "    B       loc_FF074B04 \n"
 754 
 755 "loc_FF074A28:\n"
 756 "    MOV     R0, R2 \n"
 757 "    RSBLT   R0, R0, #0 \n"
 758 "    MOVLE   R7, #0 \n"
 759 "    MOVGT   R7, #1 \n"
 760 "    CMP     R0, #0xFF \n"
 761 "    BLS     loc_FF074A68 \n"
 762 "    LDR     R0, =0x7FFF \n"
 763 "    CMP     R2, #0 \n"
 764 "    SUBLE   R0, R0, R3 \n"
 765 "    ADDLE   R0, R0, R1 \n"
 766 "    MVNLE   R1, #0x8000 \n"
 767 "    SUB     R0, R0, R1 \n"
 768 "    ADDGT   R1, R0, R3 \n"
 769 "    MVNGT   R0, #0x8000 \n"
 770 "    SUBGT   R0, R1, R0 \n"
 771 "    EOR     R7, R7, #1 \n"
 772 
 773 "loc_FF074A68:\n"
 774 "    STR     R0, [SP, #8] \n"
 775 "    LDR     R0, [R9, R4, LSL#2] \n"
 776 "    CMP     R0, #0 \n"
 777 "    ADDEQ   R0, R6, R5, LSL#2 \n"
 778 "    LDREQ   R0, [R0, #8] \n"
 779 "    BEQ     loc_FF074AA0 \n"
 780 "    ADD     R8, R6, R5, LSL#2 \n"
 781 "    ADD     R1, R8, R7, LSL#2 \n"
 782 "    LDR     R1, [R1, #0x10] \n"
 783 "    CMP     R1, R0 \n"
 784 "    BEQ     loc_FF074AA4 \n"
 785 "    LDR     R0, [R8, #0xC] \n"
 786 "    BL      sub_FF02BAB4 \n"
 787 "    LDR     R0, [R8, #8] \n"
 788 
 789 "loc_FF074AA0:\n"
 790 "    BL      sub_FF02BAB4 \n"
 791 
 792 "loc_FF074AA4:\n"
 793 "    ADD     R0, R6, R5, LSL#2 \n"
 794 "    ADD     R7, R0, R7, LSL#2 \n"
 795 "    LDR     R0, [R7, #0x10] \n"
 796 "    LDR     R1, [SP, #8] \n"
 797 "    BL      sub_FF02BAC4 \n"
 798 "    LDR     R0, [R7, #0x10] \n"
 799 "    LDR     R7, =0x2D2C \n"
 800 "    STR     R0, [R9, R4, LSL#2] \n"
 801 "    LDR     R0, [SP, #0x20] \n"
 802 "    LDRH    R1, [R0] \n"
 803 "    LDR     R0, [SP, #0x1C] \n"
 804 "    STRH    R1, [R0] \n"
 805 "    LDR     R0, [R7, R4, LSL#2] \n"
 806 "    BL      sub_FF025FF0 /*_CancelTimer*/ \n"
 807 "    LDR     R2, =0xFF0747F0 \n"
 808 "    ORR     R3, R4, #0x300 \n"
 809 "    MOV     R1, R2 \n"
 810 "    MOV     R0, #0x1F4 \n"
 811 "    BL      sub_FF025F20 /*_SetTimerAfter*/ \n"
 812 "    TST     R0, #1 \n"
 813 "    CMPNE   R0, #0x15 \n"
 814 "    STR     R0, [R7, R4, LSL#2] \n"
 815 "    BEQ     loc_FF074B10 \n"
 816 "    LDR     R2, =0x285 \n"
 817 
 818 "loc_FF074B04:\n"
 819 "    LDR     R1, =0xFF074B6C /*'RotaryEncoder.c'*/ \n"
 820 "    MOV     R0, #0 \n"
 821 "    BL      _DebugAssert \n"
 822 
 823 "loc_FF074B10:\n"
 824 "    ADD     R0, R6, R5, LSL#2 \n"
 825 "    LDR     R0, [R0, #0x18] \n"
 826 "    CMP     R0, #1 \n"
 827 "    BNE     loc_FF074BA8 \n"
 828 "    LDR     R0, =0x2D20 \n"
 829 "    LDR     R0, [R0, #0x10] \n"
 830 "    CMP     R0, #0 \n"
 831 "    BEQ     loc_FF074BA8 \n"
 832 "    LDR     R2, =0xFF0747E4 \n"
 833 "    ORR     R3, R4, #0x400 \n"
 834 "    MOV     R1, R2 \n"
 835 "    BL      sub_FF025F20 /*_SetTimerAfter*/ \n"
 836 "    TST     R0, #1 \n"
 837 "    CMPNE   R0, #0x15 \n"
 838 "    STR     R0, [R11, R4, LSL#2] \n"
 839 "    BEQ     loc_FF0748F0 \n"
 840 "    MOV     R2, #0x28C \n"
 841 
 842 "loc_FF074B54:\n"
 843 "    LDR     R1, =0xFF074B6C /*'RotaryEncoder.c'*/ \n"
 844 "    MOV     R0, #0 \n"
 845 "    BL      _DebugAssert \n"
 846 "    B       loc_FF0748F0 \n"
 847 
 848 "loc_FF074BA8:\n"
 849 "    LDR     R0, [R6, R5, LSL#2] \n"
 850 "    LDR     R1, =0xC0240000 \n"
 851 "    ADD     R0, R1, R0, LSL#8 \n"
 852 "    STR     R10, [R0, #0x100] \n"
 853 "    MOV     R1, #1 \n"
 854 "    STR     R1, [R0, #0x108] \n"
 855 "    B       loc_FF0748F0 \n"
 856 );
 857 }
 858 /*
 859     *** TEMPORARY workaround ***
 860     Init stuff to avoid asserts on cameras running DryOS r54+
 861     Execute this only once
 862  */
 863 void init_required_fw_features(void) {
 864     extern void _init_focus_eventflag();
 865     //extern void _init_zoom_semaphore(); // for MoveZoomLensWithPoint
 866 
 867     _init_focus_eventflag();
 868 }

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