root/platform/s100/sub/100d/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. taskHook
  2. boot
  3. sub_FF000364_my
  4. sub_FF0011BC_my
  5. sub_FF005F38_my
  6. taskcreate_Startup_my
  7. sub_FF00FD84_my
  8. sub_FF00FDDC_my
  9. task_Startup_my
  10. taskcreatePhySw_my
  11. spytask
  12. CreateTask_spytask
  13. init_file_modules_task
  14. JogDial_task_my

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "dryos31.h"
   5 
   6 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
   7 
   8 const char * const new_sa = &_end;
   9 
  10 // Forward declarations
  11 void CreateTask_PhySw();
  12 void CreateTask_spytask();
  13 extern volatile int jogdial_stopped;
  14 void JogDial_task_my(void);
  15 
  16 extern void task_CaptSeq();
  17 extern void task_InitFileModules();
  18 extern void task_RotaryEncoder();
  19 extern void task_MovieRecord();
  20 extern void task_ExpDrv();
  21 
  22 void taskHook(context_t **context)
  23 { 
  24         task_t *tcb=(task_t*)((char*)context-offsetof(task_t, context));
  25 
  26         // Replace firmware task addresses with ours
  27         if(tcb->entry == (void*)task_CaptSeq)                   tcb->entry = (void*)capt_seq_task; 
  28         if(tcb->entry == (void*)task_InitFileModules)   tcb->entry = (void*)init_file_modules_task;
  29         if(tcb->entry == (void*)task_RotaryEncoder)     tcb->entry = (void*)JogDial_task_my;
  30         if(tcb->entry == (void*)task_MovieRecord)               tcb->entry = (void*)movie_record_task;
  31         if(tcb->entry == (void*)task_ExpDrv)                    tcb->entry = (void*)exp_drv_task;
  32 }
  33 
  34 /*----------------------------------------------------------------------
  35         boot()
  36 
  37         Main entry point for the CHDK code
  38 -----------------------------------------------------------------------*/
  39 void __attribute__((naked,noinline)) boot() {
  40 asm volatile (
  41 "    LDR     R1, =0xC0410000 \n" 
  42 "    MOV     R0, #0 \n" 
  43 "    STR     R0, [R1] \n" 
  44 "    MOV     R1, #0x78 \n" 
  45 "    MCR     p15, 0, R1, c1, c0 \n" 
  46 "    MOV     R1, #0 \n" 
  47 "    MCR     p15, 0, R1, c7, c10, 4 \n" 
  48 "    MCR     p15, 0, R1, c7, c5 \n" 
  49 "    MCR     p15, 0, R1, c7, c6 \n" 
  50 "    MOV     R0, #0x3D \n" 
  51 "    MCR     p15, 0, R0, c6, c0 \n" 
  52 "    MOV     R0, #0xC000002F \n" 
  53 "    MCR     p15, 0, R0, c6, c1 \n" 
  54 "    MOV     R0, #0x37 \n" 
  55 "    MCR     p15, 0, R0, c6, c2 \n" 
  56 "    MOV     R0, #0x40000037 \n" 
  57 "    MCR     p15, 0, R0, c6, c3 \n" 
  58 "    MOV     R0, #0x80000017 \n" 
  59 "    MCR     p15, 0, R0, c6, c4 \n" 
  60 "    LDR     R0, =0xFF00002F \n" 
  61 "    MCR     p15, 0, R0, c6, c5 \n" 
  62 "    LDR     R0, =0xD000002B \n" 
  63 "    MCR     p15, 0, R0, c6, c7 \n" 
  64 "    MOV     R0, #0x34 \n" 
  65 "    MCR     p15, 0, R0, c2, c0 \n" 
  66 "    MOV     R0, #0x34 \n" 
  67 "    MCR     p15, 0, R0, c2, c0, 1 \n" 
  68 "    MOV     R0, #0x34 \n" 
  69 "    MCR     p15, 0, R0, c3, c0 \n" 
  70 "    LDR     R0, =0x33333330 \n" 
  71 "    MCR     p15, 0, R0, c5, c0, 2 \n" 
  72 "    LDR     R0, =0x33333330 \n" 
  73 "    MCR     p15, 0, R0, c5, c0, 3 \n" 
  74 "    MRC     p15, 0, R0, c1, c0 \n" 
  75 "    ORR     R0, R0, #0x1000 \n" 
  76 "    ORR     R0, R0, #4 \n" 
  77 "    ORR     R0, R0, #1 \n" 
  78 "    MCR     p15, 0, R0, c1, c0 \n" 
  79 "    MOV     R1, #0x80000006 \n" 
  80 "    MCR     p15, 0, R1, c9, c1 \n" 
  81 "    MOV     R1, #6 \n" 
  82 "    MCR     p15, 0, R1, c9, c1, 1 \n" 
  83 "    MRC     p15, 0, R1, c1, c0 \n" 
  84 "    ORR     R1, R1, #0x50000 \n" 
  85 "    MCR     p15, 0, R1, c1, c0 \n" 
  86 "    LDR     R2, =0xC0200000 \n" 
  87 "    MOV     R1, #1 \n" 
  88 "    STR     R1, [R2, #0x10C] \n" 
  89 "    MOV     R1, #0xFF \n" 
  90 "    STR     R1, [R2, #0xC] \n" 
  91 "    STR     R1, [R2, #0x1C] \n" 
  92 "    STR     R1, [R2, #0x2C] \n" 
  93 "    STR     R1, [R2, #0x3C] \n" 
  94 "    STR     R1, [R2, #0x4C] \n" 
  95 "    STR     R1, [R2, #0x5C] \n" 
  96 "    STR     R1, [R2, #0x6C] \n" 
  97 "    STR     R1, [R2, #0x7C] \n" 
  98 "    STR     R1, [R2, #0x8C] \n" 
  99 "    STR     R1, [R2, #0x9C] \n" 
 100 "    STR     R1, [R2, #0xAC] \n" 
 101 "    STR     R1, [R2, #0xBC] \n" 
 102 "    STR     R1, [R2, #0xCC] \n" 
 103 "    STR     R1, [R2, #0xDC] \n" 
 104 "    STR     R1, [R2, #0xEC] \n" 
 105 "    STR     R1, [R2, #0xFC] \n" 
 106 "    LDR     R1, =0xC0400008 \n" 
 107 "    LDR     R2, =0x430005 \n" 
 108 "    STR     R2, [R1] \n" 
 109 "    MOV     R1, #1 \n" 
 110 "    LDR     R2, =0xC0243100 \n" 
 111 "    STR     R2, [R1] \n" 
 112 "    LDR     R2, =0xC0242010 \n" 
 113 "    LDR     R1, [R2] \n" 
 114 "    ORR     R1, R1, #1 \n" 
 115 "    STR     R1, [R2] \n" 
 116 "    LDR     R0, =0xFF64BE5C \n" 
 117 "    LDR     R1, =0x1900 \n" 
 118 "    LDR     R3, =0x148A8 \n" 
 119 "loc_FF000144:\n"
 120 "    CMP     R1, R3 \n" 
 121 "    LDRCC   R2, [R0], #4 \n" 
 122 "    STRCC   R2, [R1], #4 \n" 
 123 "    BCC     loc_FF000144 \n" 
 124 "    LDR     R1, =0x195D34 \n" 
 125 "    MOV     R2, #0 \n" 
 126 "loc_FF00015C:\n"
 127 "    CMP     R3, R1 \n" 
 128 "    STRCC   R2, [R3], #4 \n" 
 129 "    BCC     loc_FF00015C \n" 
 130 "    B       sub_FF000364_my \n"  // -->
 131     );
 132 }
 133 
 134 
 135 void __attribute__((naked,noinline)) sub_FF000364_my() {
 136 
 137         //http://chdk.setepontos.com/index.php/topic,4194.0.html
 138         *(int*)0x1938=(int)taskHook;
 139         *(int*)0x193C=(int)taskHook; // need this for startup in Playback mode (otherwise init_file_modules_task doesn't hook properly)
 140 
 141         *(int*)(0x26E0+0x4) = (*(int*)0xC022F48C)&4 ? 0x200000 : 0x100000;
 142 
 143 asm volatile (
 144 "    LDR     R0, =0xFF0003DC \n" 
 145 "    MOV     R1, #0 \n" 
 146 "    LDR     R3, =0xFF000414 \n" 
 147 "loc_FF000370:\n"
 148 "    CMP     R0, R3 \n" 
 149 "    LDRCC   R2, [R0], #4 \n" 
 150 "    STRCC   R2, [R1], #4 \n" 
 151 "    BCC     loc_FF000370 \n" 
 152 "    LDR     R0, =0xFF000414 \n" 
 153 "    MOV     R1, #0x4B0 \n" 
 154 "    LDR     R3, =0xFF000628 \n" 
 155 "loc_FF00038C:\n"
 156 "    CMP     R0, R3 \n" 
 157 "    LDRCC   R2, [R0], #4 \n" 
 158 "    STRCC   R2, [R1], #4 \n" 
 159 "    BCC     loc_FF00038C \n" 
 160 "    MOV     R0, #0xD2 \n" 
 161 "    MSR     CPSR_cxsf, R0 \n" 
 162 "    MOV     SP, #0x1000 \n" 
 163 "    MOV     R0, #0xD3 \n" 
 164 "    MSR     CPSR_cxsf, R0 \n" 
 165 "    MOV     SP, #0x1000 \n" 
 166 "    LDR     R0, =0x6C4 \n" 
 167 "    LDR     R2, =0xEEEEEEEE \n" 
 168 "    MOV     R3, #0x1000 \n" 
 169 "loc_FF0003C0:\n"
 170 "    CMP     R0, R3 \n" 
 171 "    STRCC   R2, [R0], #4 \n" 
 172 "    BCC     loc_FF0003C0 \n" 
 173 "    BL      sub_FF0011BC_my \n" //--> 
 174     );
 175 }
 176 
 177 void __attribute__((naked,noinline)) sub_FF0011BC_my() {
 178 asm volatile (
 179 "    STR     LR, [SP, #-4]! \n" 
 180 "    SUB     SP, SP, #0x74 \n" 
 181 "    MOV     R1, #0x74 \n" 
 182 "    MOV     R0, SP \n" 
 183 "    BL      sub_FF44E0E0 \n" 
 184 "    MOV     R0, #0x67000 \n" 
 185 "    STR     R0, [SP, #4] \n" 
 186 #if defined(CHDK_NOT_IN_CANON_HEAP)
 187 "    LDR     R0, =0x195D34 \n"  // use original heap offset since CHDK is loaded in high memory
 188 #else
 189 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 190 "    LDR     R0, [R0]\n"      // 
 191 #endif
 192 "    LDR     R2, =0x55D788 \n" 
 193 "    STR     R0, [SP, #8] \n" 
 194 "    SUB     R0, R2, R0 \n" 
 195 "    STR     R0, [SP, #0xC] \n" 
 196 "    MOV     R0, #0x22 \n" 
 197 "    STR     R0, [SP, #0x18] \n" 
 198 "    MOV     R0, #0x72 \n" 
 199 "    STR     R0, [SP, #0x1C] \n" 
 200 "    LDR     R1, =0x565C00 \n" 
 201 "    LDR     R0, =0x1CD \n" 
 202 "    STR     R1, [SP] \n" 
 203 "    STR     R0, [SP, #0x20] \n" 
 204 "    MOV     R0, #0x96 \n" 
 205 "    STR     R2, [SP, #0x10] \n" 
 206 "    STR     R1, [SP, #0x14] \n" 
 207 "    STR     R0, [SP, #0x24] \n" 
 208 "    STR     R0, [SP, #0x28] \n" 
 209 "    MOV     R0, #0x64 \n" 
 210 "    STR     R0, [SP, #0x2C] \n" 
 211 "    MOV     R0, #0 \n" 
 212 "    STR     R0, [SP, #0x30] \n" 
 213 "    STR     R0, [SP, #0x34] \n" 
 214 "    MOV     R0, #0x10 \n" 
 215 "    STR     R0, [SP, #0x5C] \n" 
 216 "    MOV     R0, #0x800 \n" 
 217 "    STR     R0, [SP, #0x60] \n" 
 218 "    MOV     R0, #0xA0 \n" 
 219 "    STR     R0, [SP, #0x64] \n" 
 220 "    MOV     R0, #0x280 \n" 
 221 "    STR     R0, [SP, #0x68] \n" 
 222 "    LDR     R1, =sub_FF005F38_my \n" //-->
 223 "    MOV     R2, #0 \n" 
 224 "    MOV     R0, SP \n" 
 225 "    BL      sub_FF0034D0 \n" 
 226 "    ADD     SP, SP, #0x74 \n" 
 227 "    LDR     PC, [SP], #4 \n" 
 228     );
 229 }
 230 
 231 
 232 void __attribute__((naked,noinline)) sub_FF005F38_my() {
 233 asm volatile (
 234 "    STMFD   SP!, {R4,LR} \n" 
 235 "    BL      sub_FF000B34 \n" 
 236 "    BL      sub_FF00A390 \n" 
 237 "    CMP     R0, #0 \n" 
 238 "    LDRLT   R0, =0xFF00604C \n" 
 239 "    BLLT    sub_FF00602C \n" 
 240 "    BL      sub_FF005B70 \n" 
 241 "    CMP     R0, #0 \n" 
 242 "    LDRLT   R0, =0xFF006054 \n" 
 243 "    BLLT    sub_FF00602C \n" 
 244 "    LDR     R0, =0xFF006064 \n" 
 245 "    BL      sub_FF005C58 \n" 
 246 "    CMP     R0, #0 \n" 
 247 "    LDRLT   R0, =0xFF00606C \n" 
 248 "    BLLT    sub_FF00602C \n" 
 249 "    LDR     R0, =0xFF006064 \n" 
 250 "    BL      sub_FF003CB4 \n" 
 251 "    CMP     R0, #0 \n" 
 252 "    LDRLT   R0, =0xFF006080 \n" 
 253 "    BLLT    sub_FF00602C \n" 
 254 "    BL      sub_FF009CF8 \n" 
 255 "    CMP     R0, #0 \n" 
 256 "    LDRLT   R0, =0xFF00608C \n" 
 257 "    BLLT    sub_FF00602C \n" 
 258 "    BL      sub_FF00169C \n" 
 259 "    CMP     R0, #0 \n" 
 260 "    LDRLT   R0, =0xFF006098 \n" 
 261 "    BLLT    sub_FF00602C \n" 
 262 "    LDMFD   SP!, {R4,LR} \n" 
 263 //"    B       sub_FF00FDAC \n" 
 264 "    B       taskcreate_Startup_my \n" // patched
 265         );
 266 }
 267 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 268 asm volatile (
 269 "    STMFD   SP!, {R3,LR} \n" 
 270 "    BL      sub_FF02B598 \n" 
 271 "    BL      sub_FF02B7B0 \n" 
 272 "    MOV     R3, #0 \n" 
 273 "    STR     R3, [SP] \n" 
 274 "    LDR     R3, =sub_FF00FD84_my \n" //-->
 275 "    MOV     R2, #0x200 \n" 
 276 "    MOV     R1, #0x19 \n" 
 277 "    LDR     R0, =0xFF00FEBC \n" 
 278 "    BL      sub_FF00EAF0 \n"
 279 "    MOV     R0, #0 \n" 
 280 "    LDMFD   SP!, {R3,PC} \n"
 281     );
 282 }
 283 
 284 void __attribute__((naked,noinline)) sub_FF00FD84_my() {
 285 asm volatile (
 286 "    STMFD   SP!, {R4,LR} \n" 
 287 "    BL      sub_FF024AEC \n" 
 288 "    BL      sub_FF025C00 \n" 
 289 "    BL      sub_FF023768 \n" 
 290 "    BL      sub_FF02D9CC \n" 
 291 "    BL      sub_FF023EDC \n" 
 292 "    BL      sub_FF022C24 \n" 
 293 "    BL      sub_FF022BB0 \n" 
 294 "    LDMFD   SP!, {R4,LR} \n" 
 295 "    B       sub_FF00FDDC_my \n" //-->
 296         );
 297 }
 298 
 299 void __attribute__((naked,noinline)) sub_FF00FDDC_my() {
 300 asm volatile (
 301 "    STMFD   SP!, {R3-R7,LR} \n" 
 302 "    MOV     R6, #0 \n" 
 303 "    BL      sub_FF02D73C \n" 
 304 "    MOVS    R7, R0 \n" 
 305 "    BNE     loc_FF00FE48 \n" 
 306 "    BL      sub_FF0264BC \n" 
 307 "    CMP     R0, #0 \n" 
 308 "    BEQ     loc_FF00FE48 \n" 
 309 "    MOV     R0, #0x37 \n" 
 310 "    BL      sub_FF02BC18 \n" 
 311 "    RSBS    R5, R0, #1 \n" 
 312 "    MOVCC   R5, #0 \n" 
 313 "    MOV     R0, #0x36 \n" 
 314 "    BL      sub_FF02BC18 \n" 
 315 "    RSBS    R4, R0, #1 \n" 
 316 "    MOVCC   R4, #0 \n" 
 317 "    BL      sub_FF022BD8 \n" 
 318 "    CMP     R0, #1 \n" 
 319 "    MOVEQ   R6, #1 \n" 
 320 "    ORR     R0, R4, R5 \n" 
 321 "    ORRS    R0, R0, R6 \n" 
 322 "    BNE     loc_FF00FE68 \n" 
 323 "    BL      sub_FF0238F0 \n" 
 324 "    LDR     R1, =0x83DC00 \n" 
 325 "    MOV     R0, #0x54 \n" 
 326 "    BL      sub_FF02BC08 \n" 
 327 "loc_FF00FE44:\n"
 328 "    B       loc_FF00FE44 \n" 
 329 "loc_FF00FE48:\n"
 330 "    MOV     R0, #0x36 \n" 
 331 "    BL      sub_FF02BC18 \n" 
 332 "    RSBS    R4, R0, #1 \n" 
 333 "    MOVCC   R4, #0 \n" 
 334 "    MOV     R0, #0x37 \n" 
 335 "    BL      sub_FF02BC18 \n" 
 336 "    RSBS    R5, R0, #1 \n" 
 337 "    MOVCC   R5, #0 \n" 
 338 "loc_FF00FE68:\n"
 339 "    MOV     R3, R6 \n" 
 340 "    MOV     R2, R7 \n" 
 341 "    MOV     R1, R5 \n" 
 342 "    MOV     R0, R4 \n" 
 343 //"    BL      sub_FF024AF4 \n" // power button & startup, see sub_FF000364_my
 344 "    BL      sub_FF024AF0 \n" 
 345 "    BL      sub_FF02B598 \n" 
 346 "    LDR     R1, =0x5CE000 \n" 
 347 "    MOV     R0, #0 \n" 
 348 "    BL      sub_FF02BA08 \n" 
 349 "    BL      sub_FF02B7B0 \n" 
 350 "    MOV     R3, #0 \n" 
 351 "    STR     R3, [SP] \n" 
 352 //"    LDR     R3, =0xFF00FD34 \n" 
 353 "    LDR     R3, =task_Startup_my \n" // -->
 354 "    MOV     R2, #0 \n" 
 355 "    MOV     R1, #0x19 \n" 
 356 "    LDR     R0, =0xFF00FED0 \n" 
 357 "    BL      sub_FF00EAF0 \n" 
 358 "    MOV     R0, #0 \n" 
 359 "    LDMFD   SP!, {R3-R7,PC} \n" 
 360         );
 361 }
 362 
 363 void __attribute__((naked,noinline)) task_Startup_my() {
 364 asm volatile (
 365 "    STMFD   SP!, {R4,LR} \n" 
 366 "    BL      sub_FF0065E8 \n" 
 367 //"    BL      sub_FF02D7E0 \n" // NULLSUB
 368 //"    BL      sub_FF02D874 \n" // don't start DISKBOOT.BIN again
 369 "    BL      sub_FF02DB88 \n" 
 370 "    BL      sub_FF02D9FC \n" 
 371 "    BL      sub_FF02AD3C \n"
 372 "    BL      sub_FF02DB8C \n" 
 373 //"    BL      sub_FF02496C \n" // PhySw
 374 "    BL      CreateTask_spytask \n" // added
 375 "    BL      taskcreatePhySw_my \n"  // we do this here rather than hook so we don't waste the original stack
 376 "    BL      sub_FF028504 \n" 
 377 "    BL      sub_FF02DBA4 \n" 
 378 "    BL      sub_FF0217BC \n" 
 379 
 380 "    BL      sub_FF02250C \n"
 381 "    BL      sub_FF02D40C \n" 
 382 "    BL      sub_FF022B64 \n" 
 383 "    BL      sub_FF0224A8 \n" 
 384 "    BL      sub_FF02E830 \n" 
 385 "    BL      sub_FF02246C \n" 
 386 "    LDMFD   SP!, {R4,LR} \n" 
 387 "    B       sub_FF006708 \n"
 388      );
 389 }
 390 
 391 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 392 asm volatile (
 393 "    STMFD   SP!, {R3-R5,LR} \n" 
 394 "    LDR     R4, =0x1C3C \n" 
 395 "    LDR     R0, [R4, #4] \n" 
 396 "    CMP     R0, #0 \n" 
 397 "    BNE     loc_FF0249A0 \n" 
 398 "    MOV     R3, #0 \n" 
 399 "    STR     R3, [SP] \n" 
 400 //"    LDR     R3, =0xFF024938 \n" 
 401 //"    MOV     R2, #0x800 \n" 
 402 "    LDR     R3, =mykbd_task \n" // task_PhySw
 403 "    MOV     R2, #0x2000 \n" // stack size for new task_PhySw so we don't have to do stack switch
 404 "    MOV     R1, #0x17 \n" 
 405 "    LDR     R0, =0xFF024BEC \n" 
 406 "    BL      sub_FF02B808 \n" 
 407 "    STR     R0, [R4, #4] \n" 
 408 "loc_FF0249A0:\n"
 409 "    BL      sub_FF0595A4 \n" 
 410 "    BL      sub_FF08FBB8 \n" 
 411 "    BL      sub_FF02640C \n" 
 412 "    CMP     R0, #0 \n" 
 413 "    BNE     loc_FF0249C0 \n" 
 414 "    LDR     R1, =0x386C8 \n" 
 415 "    MOV     R0, #0 \n" 
 416 "    BL      sub_FF08FB28 \n" 
 417 "loc_FF0249C0:\n"
 418 "    LDMFD   SP!, {R3-R5,PC} \n" 
 419         );
 420 }
 421 
 422 /*----------------------------------------------------------------------
 423         spytask
 424 -----------------------------------------------------------------------*/
 425 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
 426 {
 427     core_spytask();
 428 }
 429 
 430 /*----------------------------------------------------------------------
 431         CreateTask_spytask
 432 -----------------------------------------------------------------------*/
 433 void CreateTask_spytask() {
 434         _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
 435 }
 436 
 437 /*----------------------------------------------------------------------
 438         init_file_modules_task
 439 -----------------------------------------------------------------------*/
 440 void __attribute__((naked,noinline)) init_file_modules_task() {
 441     asm volatile(
 442 "    STMFD   SP!, {R4-R6,LR} \n" 
 443 "    BL      sub_FF092164 \n" 
 444 "    LDR     R5, =0x5006 \n" 
 445 "    MOVS    R4, R0 \n" 
 446 "    MOVNE   R1, #0 \n" 
 447 "    MOVNE   R0, R5 \n" 
 448 "    BLNE    sub_FF096768 \n" 
 449 "    BL      sub_FF092190 \n" 
 450 "    BL      core_spytask_can_start\n"      // CHDK: Set "it's-safe-to-start" flag for spytask
 451 "    CMP     R4, #0 \n" 
 452 "    LDMNEFD SP!, {R4-R6,PC} \n" 
 453 "    MOV     R0, R5 \n" 
 454 "    LDMFD   SP!, {R4-R6,LR} \n" 
 455 "    MOV     R1, #0 \n" 
 456 "    B       sub_FF096768 \n" 
 457     );
 458 }
 459 
 460 /*----------------------------------------------------------------------
 461         Jogdial
 462 */
 463 // Pointer to stack location where jogdial task records previous and current
 464 // jogdial positions
 465 short *jog_position;
 466 
 467 // Firmware version @ ff05927c
 468 void __attribute__((naked,noinline)) JogDial_task_my() {
 469 asm volatile (
 470 "    STMFD   SP!, {R4-R11,LR} \n" 
 471 "    SUB     SP, SP, #0x24 \n" 
 472 "    BL      sub_FF059610 \n" 
 473 "    LDR     R12, =0x2700 \n" 
 474 "    LDR     R6, =0xFF4538CC \n" 
 475 "    MOV     R0, #0 \n" 
 476 // Save pointer for kbd.c routine - like sx40hs
 477 " ADD R10, SP, #0x10 \n"
 478 " LDR R9, =jog_position \n"
 479 " STR R10, [R9] \n"
 480 // -- 
 481 "    ADD     R10, SP, #8 \n" 
 482 "    ADD     R9, SP, #0x10 \n" 
 483 "loc_FF05929C:\n"
 484 "    ADD     R2, SP, #0x1C \n" 
 485 "    MOV     R1, #0 \n" 
 486 "    ADD     R4, R2, R0, LSL #1 \n" 
 487 "    ADD     R3, SP, #0x18 \n" 
 488 "    STRH    R1, [R4] \n" 
 489 "    ADD     R4, R3, R0, LSL #1 \n" 
 490 "    STRH    R1, [R4] \n" 
 491 "    STR     R1, [R9, R0, LSL #2] \n" 
 492 "    STR     R1, [R10, R0, LSL #2] \n" 
 493 "    ADD     R0, R0, #1 \n" 
 494 "    CMP     R0, #2 \n" 
 495 "    BLT     loc_FF05929C \n" 
 496 "loc_FF0592CC:\n"
 497 "    LDR     R0, =0x2700 \n" 
 498 "    MOV     R2, #0 \n" 
 499 "    LDR     R0, [R0, #8] \n" 
 500 "    MOV     R1, SP \n" 
 501 "    BL      sub_FF02AFD0 \n" 
 502 "    CMP     R0, #0 \n" 
 503 "    LDRNE   R1, =0x256 \n" 
 504 "    LDRNE   R0, =0xFF05952C \n" 
 505 "    BLNE    sub_FF00EDC8 \n" 
 506 "    LDR     R0, [SP] \n" 
 507 "    AND     R4, R0, #0xFF \n" 
 508 "    AND     R0, R0, #0xFF00 \n" 
 509 "    CMP     R0, #0x100 \n" 
 510 "    BEQ     loc_FF05933C \n" 
 511 "    CMP     R0, #0x200 \n" 
 512 "    BEQ     loc_FF059374 \n" 
 513 "    CMP     R0, #0x300 \n" 
 514 "    BEQ     loc_FF059574 \n" 
 515 "    CMP     R0, #0x400 \n" 
 516 "    BNE     loc_FF0592CC \n" 
 517 "    CMP     R4, #0 \n" 
 518 "    LDRNE   R1, =0x2E1 \n" 
 519 "    LDRNE   R0, =0xFF05952C \n" 
 520 "    BLNE    sub_FF00EDC8 \n" 
 521 "    RSB     R0, R4, R4, LSL #3 \n" 
 522 "    LDR     R0, [R6, R0, LSL #2] \n" 
 523 "loc_FF059334:\n"
 524 "    BL      sub_FF0595F4 \n" 
 525 "    B       loc_FF0592CC \n" 
 526 "loc_FF05933C:\n"
 527 //------------------  added code ---------------------
 528 "labelA:\n"
 529                 "LDR     R0, =jogdial_stopped\n"
 530                 "LDR     R0, [R0]\n"
 531                 "CMP     R0, #1\n"
 532                 "BNE     labelB\n"
 533                 "MOV     R0, #40\n"
 534                 "BL      _SleepTask\n" //sleep
 535                 "B       labelA\n"
 536 "labelB:\n"
 537 //------------------  original code ------------------
 538 "    LDR     R0, =0x2710 \n" 
 539 "    LDR     R0, [R0, R4, LSL #2] \n" 
 540 "    BL      sub_FF02C1F4 \n" 
 541 "    LDR     R2, =0xFF0591C8 \n" 
 542 "    ORR     R3, R4, #0x200 \n" 
 543 "    ADD     R1, R2, #0 \n" 
 544 "    MOV     R0, #0x28 \n" 
 545 "    BL      sub_FF02C110 \n" 
 546 "    TST     R0, #1 \n" 
 547 "    CMPNE   R0, #0x15 \n" 
 548 "    STR     R0, [R10, R4, LSL #2] \n" 
 549 "    BEQ     loc_FF0592CC \n" 
 550 "    MOV     R1, #0x268 \n" 
 551 "    B       loc_FF059518 \n" 
 552 "loc_FF059374:\n"
 553 "    RSB     R5, R4, R4, LSL #3 \n" 
 554 "    LDR     R0, [R6, R5, LSL #2] \n" 
 555 "    LDR     R1, =0xC0240000 \n" 
 556 "    ADD     R0, R1, R0, LSL #8 \n" 
 557 "    LDR     R0, [R0, #0x104] \n" 
 558 "    MOV     R1, R0, ASR #0x10 \n" 
 559 "    ADD     R0, SP, #0x1C \n" 
 560 "    ADD     R11, R0, R4, LSL #1 \n" 
 561 "    ADD     R0, SP, #0x18 \n" 
 562 "    ADD     R0, R0, R4, LSL #1 \n" 
 563 "    STRH    R1, [R11] \n" 
 564 "    STR     R0, [SP, #0x20] \n" 
 565 "    LDRSH   R3, [R0] \n" 
 566 "    SUB     R2, R1, R3 \n" 
 567 "    CMP     R2, #0 \n" 
 568 "    BNE     loc_FF0593F8 \n" 
 569 "    LDR     R0, [R9, R4, LSL #2] \n" 
 570 "    CMP     R0, #0 \n" 
 571 "    BEQ     loc_FF0594D4 \n" 
 572 "    LDR     R7, =0x2710 \n" 
 573 "    LDR     R0, [R7, R4, LSL #2] \n" 
 574 "    BL      sub_FF02C1F4 \n" 
 575 "    LDR     R2, =0xFF0591D4 \n" 
 576 "    ORR     R3, R4, #0x300 \n" 
 577 "    ADD     R1, R2, #0 \n" 
 578 "    MOV     R0, #0x1F4 \n" 
 579 "    BL      sub_FF02C110 \n" 
 580 "    TST     R0, #1 \n" 
 581 "    CMPNE   R0, #0x15 \n" 
 582 "    STR     R0, [R7, R4, LSL #2] \n" 
 583 "    BEQ     loc_FF0594D4 \n" 
 584 "    LDR     R1, =0x281 \n" 
 585 "    B       loc_FF0594CC \n" 
 586 "loc_FF0593F8:\n"
 587 "    MOV     R0, R2 \n" 
 588 "    RSBLT   R0, R0, #0 \n" 
 589 "    MOVLE   R7, #0 \n" 
 590 "    MOVGT   R7, #1 \n" 
 591 "    CMP     R0, #0xFF \n" 
 592 "    BLS     loc_FF059434 \n" 
 593 "    LDR     R0, =0x7FFF \n" 
 594 "    CMP     R2, #0 \n" 
 595 "    SUBLE   R0, R0, R3 \n" 
 596 "    ADDLE   R0, R0, R1 \n" 
 597 "    SUBGT   R0, R0, R1 \n" 
 598 "    ADDGT   R0, R0, R3 \n" 
 599 "    MVN     R1, #0x8000 \n" 
 600 "    SUB     R0, R0, R1 \n" 
 601 "    EOR     R7, R7, #1 \n" 
 602 "loc_FF059434:\n"
 603 "    STR     R0, [SP, #4] \n" 
 604 "    LDR     R0, [R9, R4, LSL #2] \n" 
 605 "    CMP     R0, #0 \n" 
 606 "    ADDEQ   R0, R6, R5, LSL #2 \n" 
 607 "    LDREQ   R0, [R0, #8] \n" 
 608 "    BEQ     loc_FF05946C \n" 
 609 "    ADD     R8, R6, R5, LSL #2 \n" 
 610 "    ADD     R1, R8, R7, LSL #2 \n" 
 611 "    LDR     R1, [R1, #0x10] \n" 
 612 "    CMP     R1, R0 \n" 
 613 "    BEQ     loc_FF059470 \n" 
 614 "    LDR     R0, [R8, #0xC] \n" 
 615 "    BL      sub_FF0249C4 \n" 
 616 "    LDR     R0, [R8, #8] \n" 
 617 "loc_FF05946C:\n"
 618 "    BL      sub_FF0249C4 \n" 
 619 "loc_FF059470:\n"
 620 "    ADD     R0, R6, R5, LSL #2 \n" 
 621 "    ADD     R7, R0, R7, LSL #2 \n" 
 622 "    LDR     R0, [R7, #0x10] \n" 
 623 "    LDR     R1, [SP, #4] \n" 
 624 "    BL      sub_FF0249D4 \n" 
 625 "    LDR     R0, [R7, #0x10] \n" 
 626 "    LDR     R7, =0x2710 \n" 
 627 "    STR     R0, [R9, R4, LSL #2] \n" 
 628 "    LDRH    R1, [R11] \n" 
 629 "    LDR     R0, [SP, #0x20] \n" 
 630 "    STRH    R1, [R0] \n" 
 631 "    LDR     R0, [R7, R4, LSL #2] \n" 
 632 "    BL      sub_FF02C1F4 \n" 
 633 "    LDR     R2, =0xFF0591D4 \n" 
 634 "    ORR     R3, R4, #0x300 \n" 
 635 "    ADD     R1, R2, #0 \n" 
 636 "    MOV     R0, #0x1F4 \n" 
 637 "    BL      sub_FF02C110 \n" 
 638 "    TST     R0, #1 \n" 
 639 "    CMPNE   R0, #0x15 \n" 
 640 "    STR     R0, [R7, R4, LSL #2] \n" 
 641 "    BEQ     loc_FF0594D4 \n" 
 642 "    LDR     R1, =0x2C3 \n" 
 643 "loc_FF0594CC:\n"
 644 "    LDR     R0, =0xFF05952C \n" 
 645 "    BL      sub_FF00EDC8 \n" 
 646 "loc_FF0594D4:\n"
 647 "    ADD     R0, R6, R5, LSL #2 \n" 
 648 "    LDR     R0, [R0, #0x18] \n" 
 649 "    CMP     R0, #1 \n" 
 650 "    BNE     loc_FF05956C \n" 
 651 "    LDR     R0, =0x2700 \n" 
 652 "    LDR     R0, [R0, #0xC] \n" 
 653 "    CMP     R0, #0 \n" 
 654 "    BEQ     loc_FF05956C \n" 
 655 "    LDR     R2, =0xFF0591C8 \n" 
 656 "    ORR     R3, R4, #0x400 \n" 
 657 "    ADD     R1, R2, #0 \n" 
 658 "    BL      sub_FF02C110 \n" 
 659 "    TST     R0, #1 \n" 
 660 "    CMPNE   R0, #0x15 \n" 
 661 "    STR     R0, [R10, R4, LSL #2] \n" 
 662 "    BEQ     loc_FF0592CC \n" 
 663 "    LDR     R1, =0x2CA \n" 
 664 "loc_FF059518:\n"
 665 "    LDR     R0, =0xFF05952C \n" 
 666 "    BL      sub_FF00EDC8 \n" 
 667 "    B       loc_FF0592CC \n" 
 668 "loc_FF05956C:\n"
 669 "    LDR     R0, [R6, R5, LSL #2] \n" 
 670 "    B       loc_FF059334 \n" 
 671 "loc_FF059574:\n"
 672 "    LDR     R0, [R9, R4, LSL #2] \n" 
 673 "    CMP     R0, #0 \n" 
 674 "    MOVEQ   R1, #0x2D4 \n" 
 675 "    LDREQ   R0, =0xFF05952C \n" 
 676 "    BLEQ    sub_FF00EDC8 \n" 
 677 "    RSB     R0, R4, R4, LSL #3 \n" 
 678 "    ADD     R0, R6, R0, LSL #2 \n" 
 679 "    LDR     R0, [R0, #0xC] \n" 
 680 "    BL      sub_FF0249C4 \n" 
 681 "    MOV     R0, #0 \n" 
 682 "    STR     R0, [R9, R4, LSL #2] \n" 
 683 "    B       loc_FF0592CC \n" 
 684         );
 685 
 686 }
 687 /*-----------------------------------------------------------------------*/

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