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

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

DEFINITIONS

This source file includes following definitions.
  1. CreateTask_spytask
  2. boot
  3. CreateTask_my
  4. sub_FF810380_my
  5. sub_FF811160_my
  6. sub_FF814210_my
  7. sub_FF81A21C_my
  8. sub_FF828EC8_my
  9. task_Startup_my
  10. taskcreatePhySw_my
  11. init_file_modules_task
  12. 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 #include "dryos31.h"
   8 
   9 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
  10 
  11 const char * const new_sa = &_end;
  12 
  13 // Forward declarations
  14 extern volatile int jogdial_stopped;
  15 void JogDial_task_my(void);
  16 
  17 extern void task_CaptSeq();
  18 extern void task_InitFileModules();
  19 extern void task_RotaryEncoder();
  20 extern void task_MovieRecord();
  21 extern void task_ExpDrv();
  22 extern void task_FileWrite();
  23 
  24 /*----------------------------------------------------------------------
  25     CreateTask_spytask
  26 -----------------------------------------------------------------------*/
  27 void CreateTask_spytask()
  28 {
  29     _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);
  30 }
  31 
  32 ///*----------------------------------------------------------------------
  33 // Pointer to stack location where jogdial task records previous and current
  34 // jogdial positions
  35 short *jog_position;
  36 
  37 /*----------------------------------------------------------------------
  38     boot()
  39 
  40     Main entry point for the CHDK code
  41 -----------------------------------------------------------------------*/
  42 
  43 /*************************************************************/
  44 //** boot @ 0xFF81000C - 0xFF81017C, length=93
  45 void __attribute__((naked,noinline)) boot() {
  46 asm volatile (
  47 "    LDR     R1, =0xC0410000 \n"
  48 "    MOV     R0, #0 \n"
  49 "    STR     R0, [R1] \n"
  50 "    MOV     R1, #0x78 \n"
  51 "    MCR     p15, 0, R1, c1, c0 \n"
  52 "    MOV     R1, #0 \n"
  53 "    MCR     p15, 0, R1, c7, c10, 4 \n"
  54 "    MCR     p15, 0, R1, c7, c5 \n"
  55 "    MCR     p15, 0, R1, c7, c6 \n"
  56 "    MOV     R0, #0x3D \n"
  57 "    MCR     p15, 0, R0, c6, c0 \n"
  58 "    MOV     R0, #0xC000002F \n"
  59 "    MCR     p15, 0, R0, c6, c1 \n"
  60 "    MOV     R0, #0x33 \n"
  61 "    MCR     p15, 0, R0, c6, c2 \n"
  62 "    MOV     R0, #0x40000033 \n"
  63 "    MCR     p15, 0, R0, c6, c3 \n"
  64 "    MOV     R0, #0x80000017 \n"
  65 "    MCR     p15, 0, R0, c6, c4 \n"
  66 "    LDR     R0, =0xFF80002D \n"
  67 "    MCR     p15, 0, R0, c6, c5 \n"
  68 "    MOV     R0, #0x34 \n"
  69 "    MCR     p15, 0, R0, c2, c0 \n"
  70 "    MOV     R0, #0x34 \n"
  71 "    MCR     p15, 0, R0, c2, c0, 1 \n"
  72 "    MOV     R0, #0x34 \n"
  73 "    MCR     p15, 0, R0, c3, c0 \n"
  74 "    LDR     R0, =0x3333330 \n"
  75 "    MCR     p15, 0, R0, c5, c0, 2 \n"
  76 "    LDR     R0, =0x3333330 \n"
  77 "    MCR     p15, 0, R0, c5, c0, 3 \n"
  78 "    MRC     p15, 0, R0, c1, c0 \n"
  79 "    ORR     R0, R0, #0x1000 \n"
  80 "    ORR     R0, R0, #4 \n"
  81 "    ORR     R0, R0, #1 \n"
  82 "    MCR     p15, 0, R0, c1, c0 \n"
  83 "    MOV     R1, #0x80000006 \n"
  84 "    MCR     p15, 0, R1, c9, c1 \n"
  85 "    MOV     R1, #6 \n"
  86 "    MCR     p15, 0, R1, c9, c1, 1 \n"
  87 "    MRC     p15, 0, R1, c1, c0 \n"
  88 "    ORR     R1, R1, #0x50000 \n"
  89 "    MCR     p15, 0, R1, c1, c0 \n"
  90 "    LDR     R2, =0xC0200000 \n"
  91 "    MOV     R1, #1 \n"
  92 "    STR     R1, [R2, #0x10C] \n"
  93 "    MOV     R1, #0xFF \n"
  94 "    STR     R1, [R2, #0xC] \n"
  95 "    STR     R1, [R2, #0x1C] \n"
  96 "    STR     R1, [R2, #0x2C] \n"
  97 "    STR     R1, [R2, #0x3C] \n"
  98 "    STR     R1, [R2, #0x4C] \n"
  99 "    STR     R1, [R2, #0x5C] \n"
 100 "    STR     R1, [R2, #0x6C] \n"
 101 "    STR     R1, [R2, #0x7C] \n"
 102 "    STR     R1, [R2, #0x8C] \n"
 103 "    STR     R1, [R2, #0x9C] \n"
 104 "    STR     R1, [R2, #0xAC] \n"
 105 "    STR     R1, [R2, #0xBC] \n"
 106 "    STR     R1, [R2, #0xCC] \n"
 107 "    STR     R1, [R2, #0xDC] \n"
 108 "    STR     R1, [R2, #0xEC] \n"
 109 "    STR     R1, [R2, #0xFC] \n"
 110 "    LDR     R1, =0xC0400008 \n"
 111 "    LDR     R2, =0x430005 \n"
 112 "    STR     R2, [R1] \n"
 113 "    MOV     R1, #1 \n"
 114 "    LDR     R2, =0xC0243100 \n"
 115 "    STR     R2, [R1] \n"
 116 "    LDR     R2, =0xC0242010 \n"
 117 "    LDR     R1, [R2] \n"
 118 "    ORR     R1, R1, #1 \n"
 119 "    STR     R1, [R2] \n"
 120 "    LDR     R0, =0xFFCD8B18 \n"
 121 "    LDR     R1, =0x431000 \n"
 122 "    LDR     R3, =0x44059C \n"
 123 
 124 "loc_FF81013C:\n"
 125 "    CMP     R1, R3 \n"
 126 "    LDRCC   R2, [R0], #4 \n"
 127 "    STRCC   R2, [R1], #4 \n"
 128 "    BCC     loc_FF81013C \n"
 129 "    LDR     R0, =0xFFCCAAEC \n"
 130 "    LDR     R1, =0x1900 \n"
 131 "    LDR     R3, =0xF92C \n"
 132 
 133 "loc_FF810158:\n"
 134 "    CMP     R1, R3 \n"
 135 "    LDRCC   R2, [R0], #4 \n"
 136 "    STRCC   R2, [R1], #4 \n"
 137 "    BCC     loc_FF810158 \n"
 138 "    LDR     R1, =0x1639D4 \n"
 139 "    MOV     R2, #0 \n"
 140 
 141 "loc_FF810170:\n"
 142 "    CMP     R3, R1 \n"
 143 "    STRCC   R2, [R3], #4 \n"
 144 "    BCC     loc_FF810170 \n"
 145 /* Install task hooks via 0x193x is not possible with this new dryos version
 146    So the below code patches the CreateTask function in RAM to install our
 147    hook -- ERR99
 148 */
 149 // Install CreateTask patch
 150 "    LDR     R0, =patch_CreateTask\n"   // Patch data
 151 "    LDM     R0, {R1,R2}\n"             // Get two patch instructions
 152 "    LDR     R0, =hook_CreateTask\n"    // Address to patch
 153 "    STM     R0, {R1,R2}\n"             // Store patch instructions
 154 
 155 "    B       sub_FF810380_my \n"  // --> Patched. Old value = 0xFF810380.
 156 
 157 "patch_CreateTask:\n"
 158 "    LDR     PC, [PC,#-0x4]\n"          // Do jump to absolute address CreateTask_my
 159 "    .long   CreateTask_my\n"
 160 );
 161 }
 162 
 163 /*************************************************************/
 164 //** CreateTask_my @ 0x004368B0 - 0x004368B4, length=2
 165 void __attribute__((naked,noinline)) CreateTask_my() {
 166 asm volatile (
 167 "    STMFD   SP!, {R0}\n"
 168 //R3 = Pointer to task function to create
 169 
 170 /*** INSTALL capt_seq_task() hook ***/
 171 "    LDR     R0, =task_CaptSeq\n"       // DryOS original code function ptr.
 172 "    CMP     R0, R3\n"                  // is the given taskptr equal to our searched function?
 173 "    LDREQ   R3, =capt_seq_task\n"      // if so replace with our task function base ptr.
 174 "    BEQ     exitHook\n"                // below compares not necessary if this check has found something.
 175 
 176 /*** INSTALL exp_drv_task() hook ***/
 177 "    LDR     R0, =task_ExpDrv\n"
 178 "    CMP     R0, R3\n"
 179 "    LDREQ   R3, =exp_drv_task\n"
 180 "    BEQ     exitHook\n"
 181 
 182 /*** INSTALL filewrite() hook ***/
 183 "    LDR     R0, =task_FileWrite\n"
 184 "    CMP     R0, R3\n"
 185 "    LDREQ   R3, =filewritetask\n"
 186 "    BEQ     exitHook\n"
 187 
 188 /*** INSTALL JogDial() hook ***/
 189 "    LDR     R0, =task_RotaryEncoder\n"
 190 "    CMP     R0, R3\n"
 191 "    LDREQ   R3, =JogDial_task_my\n"
 192 "    BEQ     exitHook\n"
 193 
 194 /*** INSTALL movie_record_task() hook ***/
 195 "    LDR     R0, =task_MovieRecord\n"
 196 "    CMP     R0, R3\n"
 197 "    LDREQ   R3, =movie_record_task\n"
 198 "    BEQ     exitHook\n"
 199 
 200 /*** INSTALL init_file_modules_task() hook ***/
 201 "    LDR     R0, =task_InitFileModules\n"
 202 "    CMP     R0, R3\n"
 203 "    LDREQ   R3, =init_file_modules_task\n"
 204 
 205 "exitHook:\n" 
 206 // restore overwritten registers
 207 "    LDMFD   SP!, {R0}\n"
 208 // Execute overwritten instructions from original code, then jump to firmware
 209 "    STMFD   SP!, {R1-R9,LR} \n"
 210 "    MOV     R4, R0 \n"
 211 "    LDR     PC, =0x004368B8 \n"  // Continue in firmware
 212 );
 213 }
 214 
 215 /*************************************************************/
 216 //** sub_FF810380_my @ 0xFF810380 - 0xFF8103E8, length=27
 217 void __attribute__((naked,noinline)) sub_FF810380_my() {
 218 
 219     //Replacement of sub_FF865694 for correct power-on.
 220     //(short press = playback mode, long press = record mode)
 221     if ((*(int*) 0xC0220114) & 1)       // look at power-on switch sub_ff828ec8
 222         *(int*)(0x2AF4+0x4) = 0x200000; // Playmode
 223     else
 224         *(int*)(0x2AF4+0x4) = 0x100000; // Shootingmode
 225 
 226 asm volatile (
 227 "    LDR     R0, =0xFF8103F8 \n"
 228 "    MOV     R1, #0 \n"
 229 "    LDR     R3, =0xFF810430 \n"
 230 
 231 "loc_FF81038C:\n"
 232 "    CMP     R0, R3 \n"
 233 "    LDRCC   R2, [R0], #4 \n"
 234 "    STRCC   R2, [R1], #4 \n"
 235 "    BCC     loc_FF81038C \n"
 236 "    LDR     R0, =0xFF810430 \n"
 237 "    MOV     R1, #0x4B0 \n"
 238 "    LDR     R3, =0xFF810618 \n"
 239 
 240 "loc_FF8103A8:\n"
 241 "    CMP     R0, R3 \n"
 242 "    LDRCC   R2, [R0], #4 \n"
 243 "    STRCC   R2, [R1], #4 \n"
 244 "    BCC     loc_FF8103A8 \n"
 245 "    MOV     R0, #0xD2 \n"
 246 "    MSR     CPSR_cxsf, R0 \n"
 247 "    MOV     SP, #0x1000 \n"
 248 "    MOV     R0, #0xD3 \n"
 249 "    MSR     CPSR_cxsf, R0 \n"
 250 "    MOV     SP, #0x1000 \n"
 251 "    LDR     R0, =0x698 \n"
 252 "    LDR     R2, =0xEEEEEEEE \n"
 253 "    MOV     R3, #0x1000 \n"
 254 
 255 "loc_FF8103DC:\n"
 256 "    CMP     R0, R3 \n"
 257 "    STRCC   R2, [R0], #4 \n"
 258 "    BCC     loc_FF8103DC \n"
 259 "    BL      sub_FF811160_my \n"  // --> Patched. Old value = 0xFF811160.
 260 );
 261 }
 262 
 263 /*************************************************************/
 264 //** sub_FF811160_my @ 0xFF811160 - 0xFF81120C, length=44
 265 void __attribute__((naked,noinline)) sub_FF811160_my() {
 266 asm volatile (
 267 "    STR     LR, [SP, #-4]! \n"
 268 "    SUB     SP, SP, #0x74 \n"
 269 "    MOV     R1, #0x74 \n"
 270 "    MOV     R0, SP \n"
 271 "    BL      sub_0043C3A0 \n"
 272 "    MOV     R0, #0x57000 \n"
 273 "    STR     R0, [SP, #4] \n"
 274 
 275 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 276 "    LDR     R0, =0x1639D4 \n"
 277 #else
 278 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 279 "    LDR     R0, [R0]\n"      //
 280 #endif
 281 
 282 "    LDR     R2, =0x32D440 \n"
 283 "    STR     R0, [SP, #8] \n"
 284 "    SUB     R0, R2, R0 \n"
 285 "    STR     R0, [SP, #0xC] \n"
 286 "    MOV     R0, #0x22 \n"
 287 "    STR     R0, [SP, #0x18] \n"
 288 "    MOV     R0, #0x7C \n"
 289 "    STR     R0, [SP, #0x1C] \n"
 290 "    LDR     R1, =0x335C00 \n"
 291 "    LDR     R0, =0x1CD \n"
 292 "    STR     R1, [SP] \n"
 293 "    STR     R0, [SP, #0x20] \n"
 294 "    MOV     R0, #0x96 \n"
 295 "    STR     R2, [SP, #0x10] \n"
 296 "    STR     R1, [SP, #0x14] \n"
 297 "    STR     R0, [SP, #0x24] \n"
 298 "    STR     R0, [SP, #0x28] \n"
 299 "    MOV     R0, #0x64 \n"
 300 "    STR     R0, [SP, #0x2C] \n"
 301 "    MOV     R0, #0 \n"
 302 "    STR     R0, [SP, #0x30] \n"
 303 "    STR     R0, [SP, #0x34] \n"
 304 "    MOV     R0, #0x10 \n"
 305 "    STR     R0, [SP, #0x5C] \n"
 306 "    MOV     R0, #0x800 \n"
 307 "    STR     R0, [SP, #0x60] \n"
 308 "    MOV     R0, #0xA0 \n"
 309 "    STR     R0, [SP, #0x64] \n"
 310 "    MOV     R0, #0x280 \n"
 311 "    STR     R0, [SP, #0x68] \n"
 312 "    LDR     R1, =sub_FF814210_my \n"  // --> Patched. Old value = 0xFF814210.
 313 "    MOV     R2, #0 \n"
 314 "    MOV     R0, SP \n"
 315 "    BL      sub_004327E8 \n"
 316 "    ADD     SP, SP, #0x74 \n"
 317 "    LDR     PC, [SP], #4 \n"
 318 );
 319 }
 320 
 321 /*************************************************************/
 322 //** sub_FF814210_my @ 0xFF814210 - 0xFF814284, length=30
 323 void __attribute__((naked,noinline)) sub_FF814210_my() {
 324 asm volatile (
 325 "    STMFD   SP!, {R4,LR} \n"
 326 "    BL      sub_FF810ADC \n"
 327 "    BL      sub_FF8150FC \n"
 328 "    CMP     R0, #0 \n"
 329 "    LDRLT   R0, =0xFF814324 /*'dmSetup'*/ \n"
 330 "    BLLT    _err_init_task \n"
 331 "    BL      sub_FF813E48 \n"
 332 "    CMP     R0, #0 \n"
 333 "    LDRLT   R0, =0xFF81432C /*'termDriverInit'*/ \n"
 334 "    BLLT    _err_init_task \n"
 335 "    LDR     R0, =0xFF81433C /*'/_term'*/ \n"
 336 "    BL      sub_FF813F30 \n"
 337 "    CMP     R0, #0 \n"
 338 "    LDRLT   R0, =0xFF814344 /*'termDeviceCreate'*/ \n"
 339 "    BLLT    _err_init_task \n"
 340 "    LDR     R0, =0xFF81433C /*'/_term'*/ \n"
 341 "    BL      sub_FF812950 \n"
 342 "    CMP     R0, #0 \n"
 343 "    LDRLT   R0, =0xFF814358 /*'stdioSetup'*/ \n"
 344 "    BLLT    _err_init_task \n"
 345 "    BL      sub_FF814A98 \n"
 346 "    CMP     R0, #0 \n"
 347 "    LDRLT   R0, =0xFF814364 /*'stdlibSetup'*/ \n"
 348 "    BLLT    _err_init_task \n"
 349 "    BL      sub_FF811650 \n"
 350 "    CMP     R0, #0 \n"
 351 "    LDRLT   R0, =0xFF814370 /*'armlib_setup'*/ \n"
 352 "    BLLT    _err_init_task \n"
 353 "    LDMFD   SP!, {R4,LR} \n"
 354 "    B       sub_FF81A21C_my \n"  // --> Patched. Old value = 0xFF81A21C.
 355 );
 356 }
 357 
 358 /*************************************************************/
 359 //** sub_FF81A21C_my @ 0xFF81A21C - 0xFF81A298, length=32
 360 void __attribute__((naked,noinline)) sub_FF81A21C_my() {
 361 asm volatile (
 362 "    STMFD   SP!, {R3,LR} \n"
 363 "    BL      sub_FF830550 \n"
 364 "    CMP     R0, #0 \n"
 365 "    BNE     loc_FF81A23C \n"
 366 "    BL      sub_FF82AA28 /*_IsNormalCameraMode_FW*/ \n"
 367 "    CMP     R0, #0 \n"
 368 "    MOVNE   R0, #1 \n"
 369 "    BNE     loc_FF81A240 \n"
 370 
 371 "loc_FF81A23C:\n"
 372 "    MOV     R0, #0 \n"
 373 
 374 "loc_FF81A240:\n"
 375 "    BL      sub_FF828EC8_my \n"  // --> Patched. Old value = 0xFF828EC8.
 376 "    CMP     R0, #0 \n"
 377 "    BNE     loc_FF81A264 \n"
 378 "    BL      sub_FF828540 \n"
 379 "    LDR     R1, =0xC0220000 \n"
 380 "    MOV     R0, #0x44 \n"
 381 "    STR     R0, [R1, #0x12C] \n"
 382 "    BL      sub_FF828684 \n"
 383 
 384 "loc_FF81A260:\n"
 385 "    B       loc_FF81A260 \n"
 386 
 387 "loc_FF81A264:\n"
 388 "    BL      sub_0043786C \n"
 389 "    LDR     R1, =0x38E000 \n"
 390 "    MOV     R0, #0 \n"
 391 "    BL      sub_FF82EB8C \n"
 392 "    BL      sub_00437A84 /*_EnableDispatch*/ \n"
 393 "    MOV     R3, #0 \n"
 394 "    STR     R3, [SP] \n"
 395 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF81A1B4.
 396 "    MOV     R2, #0 \n"
 397 "    MOV     R1, #0x19 \n"
 398 "    LDR     R0, =0xFF81A2A8 /*'Startup'*/ \n"
 399 "    BL      _CreateTask \n"
 400 "    MOV     R0, #0 \n"
 401 "    LDMFD   SP!, {R3,PC} \n"
 402 );
 403 }
 404 
 405 /*************************************************************/
 406 //** sub_FF828EC8_my @ 0xFF828EC8 - 0xFF828F20, length=23
 407 void __attribute__((naked,noinline)) sub_FF828EC8_my() {
 408 asm volatile (
 409 "    STMFD   SP!, {R4-R6,LR} \n"
 410 "    MOV     R6, R0 \n"
 411 //"  BL      _sub_FF86568C \n"  // --> Nullsub call removed.
 412 "    LDR     R0, =0xC0220114 \n"
 413 "    BL      sub_FF865ED8 \n"
 414 "    MOV     R4, #1 \n"
 415 "    BIC     R5, R4, R0 \n"
 416 "    LDR     R0, =0xC022010C \n"
 417 "    BL      sub_FF865ED8 \n"
 418 "    CMP     R6, #0 \n"
 419 "    BIC     R4, R4, R0 \n"
 420 "    BEQ     loc_FF828F00 \n"
 421 "    ORRS    R0, R5, R4 \n"
 422 "    LDMEQFD SP!, {R4-R6,PC} \n"
 423 
 424 "loc_FF828F00:\n"
 425 "    BL      sub_FF830550 \n"
 426 "    MOV     R2, R0 \n"
 427 "    MOV     R3, #0 \n"
 428 "    MOV     R1, R4 \n"
 429 "    MOV     R0, R5 \n"
 430 //"  BL      _sub_FF865694 \n"  // Disable StartUpChecks
 431 //"  BL      _sub_FF865690 \n"  // --> Nullsub call removed.
 432 "    MOV     R0, #1 \n"
 433 "    LDMFD   SP!, {R4-R6,PC} \n"
 434 );
 435 }
 436 
 437 /*************************************************************/
 438 //** task_Startup_my @ 0xFF81A1B4 - 0xFF81A218, length=26
 439 void __attribute__((naked,noinline)) task_Startup_my() {
 440 asm volatile (
 441 "    STMFD   SP!, {R4,LR} \n"
 442 "    BL      sub_FF814850 \n"
 443 "    BL      sub_FF82A04C \n"
 444 "    BL      sub_FF8281EC \n"
 445 //"  BL      _sub_FF865EEC \n"  // --> Nullsub call removed.
 446 "    BL      sub_FF830784 \n"
 447 //"  BL      _sub_FF83062C \n"  // load DISKBOOT.BIN
 448 "    BL      sub_FF83090C \n"
 449 "    BL      sub_FF830AD8 \n"
 450 "    BL      sub_FF8308D0 \n"
 451 "    BL      sub_FF8307B4 \n"
 452 "    BL      sub_FF82EAC0 \n"
 453 "    BL      sub_FF830AE0 \n"
 454 "    BL      CreateTask_spytask\n" // added
 455 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFF828D68.
 456 "    BL      sub_FF82C830 \n"
 457 "    BL      sub_FF8A774C \n"
 458 "    BL      sub_FF826214 \n"
 459 "    BL      sub_FF827C0C \n"
 460 "    BL      sub_FF83030C \n"
 461 "    BL      sub_FF8281A0 \n"
 462 "    BL      sub_FF827BAC \n"
 463 "    BL      sub_FF853E74 \n"
 464 "    BL      sub_FF826EA4 \n"
 465 "    BL      sub_FF827B70 \n"
 466 "    LDMFD   SP!, {R4,LR} \n"
 467 "    B       sub_FF814970 \n"
 468 );
 469 }
 470 
 471 /*************************************************************/
 472 //** taskcreatePhySw_my @ 0xFF828D68 - 0xFF828DBC, length=22
 473 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 474 asm volatile (
 475 "    STMFD   SP!, {R3-R5,LR} \n"
 476 "    LDR     R4, =0x1D30 \n"
 477 "    LDR     R0, [R4, #4] \n"
 478 "    CMP     R0, #0 \n"
 479 "    BNE     loc_FF828D9C \n"
 480 "    MOV     R3, #0 \n"
 481 "    STR     R3, [SP] \n"
 482 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF828D34.
 483 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw so we don't have to do stack switch
 484 "    MOV     R1, #0x17 \n"
 485 "    LDR     R0, =0xFF829018 /*'PhySw'*/ \n"
 486 "    BL      sub_00437ADC /*_CreateTaskStrictly*/ \n"
 487 "    STR     R0, [R4, #4] \n"
 488 
 489 "loc_FF828D9C:\n"
 490 "    BL      sub_FF866348 \n"
 491 "    BL      sub_FF8934C8 \n"
 492 "    BL      sub_FF82A978 /*_IsFactoryMode_FW*/ \n"
 493 "    CMP     R0, #0 \n"
 494 "    BNE     loc_FF828DBC \n"
 495 "    LDR     R1, =0x33964 \n"
 496 "    MOV     R0, #0 \n"
 497 "    BL      sub_FF893434 /*_OpLog.Start_FW*/ \n"
 498 
 499 "loc_FF828DBC:\n"
 500 "    LDMFD   SP!, {R3-R5,PC} \n"
 501 );
 502 }
 503 
 504 /*************************************************************/
 505 //** init_file_modules_task @ 0xFF856B18 - 0xFF856B4C, length=14
 506 void __attribute__((naked,noinline)) init_file_modules_task() {
 507 asm volatile (
 508 "    STMFD   SP!, {R4-R6,LR} \n"
 509 "    BL      sub_FF895A08 \n"
 510 "    LDR     R5, =0x5006 \n"
 511 "    MOVS    R4, R0 \n"
 512 "    MOVNE   R1, #0 \n"
 513 "    MOVNE   R0, R5 \n"
 514 "    BLNE    _PostLogicalEventToUI \n"
 515 "    BL      sub_FF895A34 \n"
 516 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 517 "    CMP     R4, #0 \n"
 518 "    LDMNEFD SP!, {R4-R6,PC} \n"
 519 "    MOV     R0, R5 \n"
 520 "    LDMFD   SP!, {R4-R6,LR} \n"
 521 "    MOV     R1, #0 \n"
 522 "    B       _PostLogicalEventToUI \n"
 523 );
 524 }
 525 
 526 /*************************************************************/
 527 //** JogDial_task_my @ 0xFF86601C - 0xFF866344, length=203
 528 void __attribute__((naked,noinline)) JogDial_task_my() {
 529 asm volatile (
 530 "    STMFD   SP!, {R4-R11,LR} \n"
 531 "    SUB     SP, SP, #0x1C \n"
 532 "    BL      sub_FF8663B4 \n"
 533 "    LDR     R12, =0x2B08 \n"
 534 "    LDR     R6, =0xFFBA4C34 \n"
 535 "    MOV     R0, #0 \n"
 536 "    ADD     R10, SP, #8 \n"
 537 "    ADD     R9, SP, #0xC \n"
 538 
 539 // Save pointer for kbd.c routine
 540 "    LDR     R2, =jog_position \n"
 541 "    STR     R9, [R2] \n"
 542 
 543 
 544 "loc_FF86603C:\n"
 545 "    ADD     R2, SP, #0x14 \n"
 546 "    MOV     R1, #0 \n"
 547 "    ADD     R4, R2, R0, LSL#1 \n"
 548 "    ADD     R3, SP, #0x10 \n"
 549 "    STRH    R1, [R4] \n"
 550 "    ADD     R4, R3, R0, LSL#1 \n"
 551 "    STRH    R1, [R4] \n"
 552 "    STR     R1, [R9, R0, LSL#2] \n"
 553 "    STR     R1, [R10, R0, LSL#2] \n"
 554 "    ADD     R0, R0, #1 \n"
 555 "    CMP     R0, #1 \n"
 556 "    BLT     loc_FF86603C \n"
 557 
 558 "loc_FF86606C:\n"
 559 "    LDR     R0, =0x2B08 \n"
 560 "    MOV     R2, #0 \n"
 561 "    LDR     R0, [R0, #8] \n"
 562 "    MOV     R1, SP \n"
 563 "    BL      sub_004372A4 /*_ReceiveMessageQueue*/ \n"
 564 "    CMP     R0, #0 \n"
 565 "    LDRNE   R1, =0x20B \n"
 566 "    LDRNE   R0, =0xFF8662CC /*'RotaryEncoder.c'*/ \n"
 567 "    BLNE    _DebugAssert \n"
 568 "    LDR     R0, [SP] \n"
 569 "    AND     R4, R0, #0xFF \n"
 570 "    AND     R0, R0, #0xFF00 \n"
 571 "    CMP     R0, #0x100 \n"
 572 "    BEQ     loc_FF8660DC \n"
 573 "    CMP     R0, #0x200 \n"
 574 "    BEQ     loc_FF866114 \n"
 575 "    CMP     R0, #0x300 \n"
 576 "    BEQ     loc_FF866318 \n"
 577 "    CMP     R0, #0x400 \n"
 578 "    BNE     loc_FF86606C \n"
 579 "    CMP     R4, #0 \n"
 580 "    LDRNE   R1, =0x285 \n"
 581 "    LDRNE   R0, =0xFF8662CC /*'RotaryEncoder.c'*/ \n"
 582 "    BLNE    _DebugAssert \n"
 583 "    RSB     R0, R4, R4, LSL#3 \n"
 584 "    LDR     R0, [R6, R0, LSL#2] \n"
 585 
 586 "loc_FF8660D4:\n"
 587 "    BL      sub_FF866398 \n"
 588 "    B       loc_FF86606C \n"
 589 
 590 "loc_FF8660DC:\n"
 591 //------------------  added code ---------------------
 592 "labelA:\n"
 593 "    LDR     R0, =jogdial_stopped\n"
 594 "    LDR     R0, [R0]\n"
 595 "    CMP     R0, #1\n"
 596 "    BNE     labelB\n"
 597 "    MOV     R0, #40\n"
 598 "    BL      _SleepTask\n"
 599 "    B       labelA\n"
 600 "labelB:\n"
 601 //------------------  original code ------------------
 602 "    LDR     R0, =0x2B14 \n"
 603 "    LDR     R0, [R0, R4, LSL#2] \n"
 604 "    BL      sub_FF82F104 /*_CancelTimer*/ \n"
 605 "    LDR     R2, =0xFF865F68 \n"
 606 "    ORR     R3, R4, #0x200 \n"
 607 "    MOV     R1, R2 \n"
 608 "    MOV     R0, #0x28 \n"
 609 "    BL      sub_FF82F020 /*_SetTimerAfter*/ \n"
 610 "    TST     R0, #1 \n"
 611 "    CMPNE   R0, #0x15 \n"
 612 "    STR     R0, [R10, R4, LSL#2] \n"
 613 "    BEQ     loc_FF86606C \n"
 614 "    LDR     R1, =0x21D \n"
 615 "    B       loc_FF8662B8 \n"
 616 
 617 "loc_FF866114:\n"
 618 "    RSB     R5, R4, R4, LSL#3 \n"
 619 "    LDR     R0, [R6, R5, LSL#2] \n"
 620 "    LDR     R1, =0xC0240000 \n"
 621 "    ADD     R0, R1, R0, LSL#8 \n"
 622 "    LDR     R0, [R0, #0x104] \n"
 623 "    MOV     R1, R0, ASR#16 \n"
 624 "    ADD     R0, SP, #0x14 \n"
 625 "    ADD     R11, R0, R4, LSL#1 \n"
 626 "    ADD     R0, SP, #0x10 \n"
 627 "    ADD     R0, R0, R4, LSL#1 \n"
 628 "    STRH    R1, [R11] \n"
 629 "    STR     R0, [SP, #0x18] \n"
 630 "    LDRSH   R3, [R0] \n"
 631 "    SUB     R2, R1, R3 \n"
 632 "    CMP     R2, #0 \n"
 633 "    BNE     loc_FF866198 \n"
 634 "    LDR     R0, [R9, R4, LSL#2] \n"
 635 "    CMP     R0, #0 \n"
 636 "    BEQ     loc_FF866274 \n"
 637 "    LDR     R7, =0x2B14 \n"
 638 "    LDR     R0, [R7, R4, LSL#2] \n"
 639 "    BL      sub_FF82F104 /*_CancelTimer*/ \n"
 640 "    LDR     R2, =0xFF865F74 \n"
 641 "    ORR     R3, R4, #0x300 \n"
 642 "    MOV     R1, R2 \n"
 643 "    MOV     R0, #0x1F4 \n"
 644 "    BL      sub_FF82F020 /*_SetTimerAfter*/ \n"
 645 "    TST     R0, #1 \n"
 646 "    CMPNE   R0, #0x15 \n"
 647 "    STR     R0, [R7, R4, LSL#2] \n"
 648 "    BEQ     loc_FF866274 \n"
 649 "    LDR     R1, =0x236 \n"
 650 "    B       loc_FF86626C \n"
 651 
 652 "loc_FF866198:\n"
 653 "    MOV     R0, R2 \n"
 654 "    RSBLT   R0, R0, #0 \n"
 655 "    MOVLE   R7, #0 \n"
 656 "    MOVGT   R7, #1 \n"
 657 "    CMP     R0, #0xFF \n"
 658 "    BLS     loc_FF8661D4 \n"
 659 "    LDR     R0, =0x7FFF \n"
 660 "    CMP     R2, #0 \n"
 661 "    SUBLE   R0, R0, R3 \n"
 662 "    ADDLE   R0, R0, R1 \n"
 663 "    SUBGT   R0, R0, R1 \n"
 664 "    ADDGT   R0, R0, R3 \n"
 665 "    MVN     R1, #0x8000 \n"
 666 "    SUB     R0, R0, R1 \n"
 667 "    EOR     R7, R7, #1 \n"
 668 
 669 "loc_FF8661D4:\n"
 670 "    STR     R0, [SP, #4] \n"
 671 "    LDR     R0, [R9, R4, LSL#2] \n"
 672 "    CMP     R0, #0 \n"
 673 "    ADDEQ   R0, R6, R5, LSL#2 \n"
 674 "    LDREQ   R0, [R0, #8] \n"
 675 "    BEQ     loc_FF86620C \n"
 676 "    ADD     R8, R6, R5, LSL#2 \n"
 677 "    ADD     R1, R8, R7, LSL#2 \n"
 678 "    LDR     R1, [R1, #0x10] \n"
 679 "    CMP     R1, R0 \n"
 680 "    BEQ     loc_FF866210 \n"
 681 "    LDR     R0, [R8, #0xC] \n"
 682 "    BL      sub_FF828DC0 \n"
 683 "    LDR     R0, [R8, #8] \n"
 684 
 685 "loc_FF86620C:\n"
 686 "    BL      sub_FF828DC0 \n"
 687 
 688 "loc_FF866210:\n"
 689 "    ADD     R0, R6, R5, LSL#2 \n"
 690 "    ADD     R7, R0, R7, LSL#2 \n"
 691 "    LDR     R0, [R7, #0x10] \n"
 692 "    LDR     R1, [SP, #4] \n"
 693 "    BL      sub_FF828DD0 \n"
 694 "    LDR     R0, [R7, #0x10] \n"
 695 "    LDR     R7, =0x2B14 \n"
 696 "    STR     R0, [R9, R4, LSL#2] \n"
 697 "    LDRH    R1, [R11] \n"
 698 "    LDR     R0, [SP, #0x18] \n"
 699 "    STRH    R1, [R0] \n"
 700 "    LDR     R0, [R7, R4, LSL#2] \n"
 701 "    BL      sub_FF82F104 /*_CancelTimer*/ \n"
 702 "    LDR     R2, =0xFF865F74 \n"
 703 "    ORR     R3, R4, #0x300 \n"
 704 "    MOV     R1, R2 \n"
 705 "    MOV     R0, #0x1F4 \n"
 706 "    BL      sub_FF82F020 /*_SetTimerAfter*/ \n"
 707 "    TST     R0, #1 \n"
 708 "    CMPNE   R0, #0x15 \n"
 709 "    STR     R0, [R7, R4, LSL#2] \n"
 710 "    BEQ     loc_FF866274 \n"
 711 "    LDR     R1, =0x267 \n"
 712 
 713 "loc_FF86626C:\n"
 714 "    LDR     R0, =0xFF8662CC /*'RotaryEncoder.c'*/ \n"
 715 "    BL      _DebugAssert \n"
 716 
 717 "loc_FF866274:\n"
 718 "    ADD     R0, R6, R5, LSL#2 \n"
 719 "    LDR     R0, [R0, #0x18] \n"
 720 "    CMP     R0, #1 \n"
 721 "    BNE     loc_FF866310 \n"
 722 "    LDR     R0, =0x2B08 \n"
 723 "    LDR     R0, [R0, #0x10] \n"
 724 "    CMP     R0, #0 \n"
 725 "    BEQ     loc_FF866310 \n"
 726 "    LDR     R2, =0xFF865F68 \n"
 727 "    ORR     R3, R4, #0x400 \n"
 728 "    MOV     R1, R2 \n"
 729 "    BL      sub_FF82F020 /*_SetTimerAfter*/ \n"
 730 "    TST     R0, #1 \n"
 731 "    CMPNE   R0, #0x15 \n"
 732 "    STR     R0, [R10, R4, LSL#2] \n"
 733 "    BEQ     loc_FF86606C \n"
 734 "    LDR     R1, =0x26E \n"
 735 
 736 "loc_FF8662B8:\n"
 737 "    LDR     R0, =0xFF8662CC /*'RotaryEncoder.c'*/ \n"
 738 "    BL      _DebugAssert \n"
 739 "    B       loc_FF86606C \n"
 740 
 741 "loc_FF866310:\n"
 742 "    LDR     R0, [R6, R5, LSL#2] \n"
 743 "    B       loc_FF8660D4 \n"
 744 
 745 "loc_FF866318:\n"
 746 "    LDR     R0, [R9, R4, LSL#2] \n"
 747 "    CMP     R0, #0 \n"
 748 "    MOVEQ   R1, #0x278 \n"
 749 "    LDREQ   R0, =0xFF8662CC /*'RotaryEncoder.c'*/ \n"
 750 "    BLEQ    _DebugAssert \n"
 751 "    RSB     R0, R4, R4, LSL#3 \n"
 752 "    ADD     R0, R6, R0, LSL#2 \n"
 753 "    LDR     R0, [R0, #0xC] \n"
 754 "    BL      sub_FF828DC0 \n"
 755 "    MOV     R0, #0 \n"
 756 "    STR     R0, [R9, R4, LSL#2] \n"
 757 "    B       loc_FF86606C \n"
 758 );
 759 }

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