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

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