root/platform/sx20/sub/100f/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. taskHook
  2. CreateTask_spytask
  3. boot
  4. sub_FF810354_my
  5. sub_FF811178_my
  6. sub_FF815E34_my
  7. taskcreate_Startup_my
  8. task_Startup_my
  9. taskcreatePhySw_my
  10. init_file_modules_task
  11. sub_FF88FB88_my
  12. sub_FF86EDF4_my
  13. sub_FF86EA28_my
  14. sub_FF86E724_my
  15. 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_ExpDrv();
  19 extern void task_FileWrite();
  20 extern void task_InitFileModules();
  21 extern void task_MovieRecord();
  22 extern void task_RotaryEncoder();
  23 
  24 void taskHook(context_t **context)
  25 {
  26     task_t *tcb=(task_t*)((char*)context-offsetof(task_t, context));
  27 
  28     // Replace firmware task addresses with ours
  29     if(tcb->entry == (void*)task_CaptSeq)           tcb->entry = (void*)capt_seq_task;
  30     if(tcb->entry == (void*)task_InitFileModules)   tcb->entry = (void*)init_file_modules_task;
  31     if(tcb->entry == (void*)task_MovieRecord)       tcb->entry = (void*)movie_record_task;
  32     if(tcb->entry == (void*)task_ExpDrv)            tcb->entry = (void*)exp_drv_task;
  33     if(tcb->entry == (void*)task_RotaryEncoder)     tcb->entry = (void*)JogDial_task_my;
  34     if(tcb->entry == (void*)task_FileWrite)         tcb->entry = (void*)filewritetask;
  35 }
  36 
  37 /*----------------------------------------------------------------------
  38     CreateTask_spytask
  39 -----------------------------------------------------------------------*/
  40 void CreateTask_spytask() {
  41     _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);
  42 };
  43 
  44 ///*----------------------------------------------------------------------
  45 // Pointer to stack location where jogdial task records previous and current
  46 // jogdial positions
  47 short *jog_position;
  48 
  49 
  50 /*----------------------------------------------------------------------
  51     boot()
  52 
  53     Main entry point for the CHDK code
  54 -----------------------------------------------------------------------*/
  55 
  56 /*************************************************************/
  57 //** boot @ 0xFF81000C - 0xFF810160, length=86
  58 void __attribute__((naked,noinline)) boot() {
  59 asm volatile (
  60 "    LDR     R1, =0xC0410000 \n"
  61 "    MOV     R0, #0 \n"
  62 "    STR     R0, [R1] \n"
  63 "    MOV     R1, #0x78 \n"
  64 "    MCR     p15, 0, R1, c1, c0 \n"
  65 "    MOV     R1, #0 \n"
  66 "    MCR     p15, 0, R1, c7, c10, 4 \n"
  67 "    MCR     p15, 0, R1, c7, c5 \n"
  68 "    MCR     p15, 0, R1, c7, c6 \n"
  69 "    MOV     R0, #0x3D \n"
  70 "    MCR     p15, 0, R0, c6, c0 \n"
  71 "    MOV     R0, #0xC000002F \n"
  72 "    MCR     p15, 0, R0, c6, c1 \n"
  73 "    MOV     R0, #0x33 \n"
  74 "    MCR     p15, 0, R0, c6, c2 \n"
  75 "    MOV     R0, #0x40000033 \n"
  76 "    MCR     p15, 0, R0, c6, c3 \n"
  77 "    MOV     R0, #0x80000017 \n"
  78 "    MCR     p15, 0, R0, c6, c4 \n"
  79 "    LDR     R0, =0xFF80002D \n"
  80 "    MCR     p15, 0, R0, c6, c5 \n"
  81 "    MOV     R0, #0x34 \n"
  82 "    MCR     p15, 0, R0, c2, c0 \n"
  83 "    MOV     R0, #0x34 \n"
  84 "    MCR     p15, 0, R0, c2, c0, 1 \n"
  85 "    MOV     R0, #0x34 \n"
  86 "    MCR     p15, 0, R0, c3, c0 \n"
  87 "    LDR     R0, =0x3333330 \n"
  88 "    MCR     p15, 0, R0, c5, c0, 2 \n"
  89 "    LDR     R0, =0x3333330 \n"
  90 "    MCR     p15, 0, R0, c5, c0, 3 \n"
  91 "    MRC     p15, 0, R0, c1, c0 \n"
  92 "    ORR     R0, R0, #0x1000 \n"
  93 "    ORR     R0, R0, #4 \n"
  94 "    ORR     R0, R0, #1 \n"
  95 "    MCR     p15, 0, R0, c1, c0 \n"
  96 "    MOV     R1, #0x80000006 \n"
  97 "    MCR     p15, 0, R1, c9, c1 \n"
  98 "    MOV     R1, #6 \n"
  99 "    MCR     p15, 0, R1, c9, c1, 1 \n"
 100 "    MRC     p15, 0, R1, c1, c0 \n"
 101 "    ORR     R1, R1, #0x50000 \n"
 102 "    MCR     p15, 0, R1, c1, c0 \n"
 103 "    LDR     R2, =0xC0200000 \n"
 104 "    MOV     R1, #1 \n"
 105 "    STR     R1, [R2, #0x10C] \n"
 106 "    MOV     R1, #0xFF \n"
 107 "    STR     R1, [R2, #0xC] \n"
 108 "    STR     R1, [R2, #0x1C] \n"
 109 "    STR     R1, [R2, #0x2C] \n"
 110 "    STR     R1, [R2, #0x3C] \n"
 111 "    STR     R1, [R2, #0x4C] \n"
 112 "    STR     R1, [R2, #0x5C] \n"
 113 "    STR     R1, [R2, #0x6C] \n"
 114 "    STR     R1, [R2, #0x7C] \n"
 115 "    STR     R1, [R2, #0x8C] \n"
 116 "    STR     R1, [R2, #0x9C] \n"
 117 "    STR     R1, [R2, #0xAC] \n"
 118 "    STR     R1, [R2, #0xBC] \n"
 119 "    STR     R1, [R2, #0xCC] \n"
 120 "    STR     R1, [R2, #0xDC] \n"
 121 "    STR     R1, [R2, #0xEC] \n"
 122 "    STR     R1, [R2, #0xFC] \n"
 123 "    LDR     R1, =0xC0400008 \n"
 124 "    LDR     R2, =0x430005 \n"
 125 "    STR     R2, [R1] \n"
 126 "    MOV     R1, #1 \n"
 127 "    LDR     R2, =0xC0243100 \n"
 128 "    STR     R2, [R1] \n"
 129 "    LDR     R2, =0xC0242010 \n"
 130 "    LDR     R1, [R2] \n"
 131 "    ORR     R1, R1, #1 \n"
 132 "    STR     R1, [R2] \n"
 133 "    LDR     R0, =0xFFC0EF3C \n"
 134 "    LDR     R1, =0x1900 \n"
 135 "    LDR     R3, =0xE7F4 \n"
 136 
 137 "loc_FF81013C:\n"
 138 "    CMP     R1, R3 \n"
 139 "    LDRCC   R2, [R0], #4 \n"
 140 "    STRCC   R2, [R1], #4 \n"
 141 "    BCC     loc_FF81013C \n"
 142 "    LDR     R1, =0x13DD20 \n"
 143 "    MOV     R2, #0 \n"
 144 
 145 "loc_FF810154:\n"
 146 "    CMP     R3, R1 \n"
 147 "    STRCC   R2, [R3], #4 \n"
 148 "    BCC     loc_FF810154 \n"
 149 "    B       sub_FF810354_my \n"  // --> Patched. Old value = 0xFF810354.
 150 );
 151 }
 152 
 153 /*************************************************************/
 154 //** sub_FF810354_my @ 0xFF810354 - 0xFF8103BC, length=27
 155 void __attribute__((naked,noinline)) sub_FF810354_my() {
 156 
 157     //http://chdk.setepontos.com/index.php/topic,4194.0.html
 158     *(int*)0x1934=(int)taskHook;
 159     *(int*)0x1938=(int)taskHook;
 160 
 161     // replacement of sub_FF85E718 for correct power-on.
 162     *(int*)(0x2564)= (*(int*)0xC0220134)&1 ? 0x2000000 : 0x1000000; 
 163     
 164 
 165 asm volatile (
 166 "    LDR     R0, =0xFF8103CC \n"
 167 "    MOV     R1, #0 \n"
 168 "    LDR     R3, =0xFF810404 \n"
 169 
 170 "loc_FF810360:\n"
 171 "    CMP     R0, R3 \n"
 172 "    LDRCC   R2, [R0], #4 \n"
 173 "    STRCC   R2, [R1], #4 \n"
 174 "    BCC     loc_FF810360 \n"
 175 "    LDR     R0, =0xFF810404 \n"
 176 "    MOV     R1, #0x4B0 \n"
 177 "    LDR     R3, =0xFF810618 \n"
 178 
 179 "loc_FF81037C:\n"
 180 "    CMP     R0, R3 \n"
 181 "    LDRCC   R2, [R0], #4 \n"
 182 "    STRCC   R2, [R1], #4 \n"
 183 "    BCC     loc_FF81037C \n"
 184 "    MOV     R0, #0xD2 \n"
 185 "    MSR     CPSR_cxsf, R0 \n"
 186 "    MOV     SP, #0x1000 \n"
 187 "    MOV     R0, #0xD3 \n"
 188 "    MSR     CPSR_cxsf, R0 \n"
 189 "    MOV     SP, #0x1000 \n"
 190 "    LDR     R0, =0x6C4 \n"
 191 "    LDR     R2, =0xEEEEEEEE \n"
 192 "    MOV     R3, #0x1000 \n"
 193 
 194 "loc_FF8103B0:\n"
 195 "    CMP     R0, R3 \n"
 196 "    STRCC   R2, [R0], #4 \n"
 197 "    BCC     loc_FF8103B0 \n"
 198 "    BL      sub_FF811178_my \n"  // --> Patched. Old value = 0xFF811178.
 199 );
 200 }
 201 
 202 /*************************************************************/
 203 //** sub_FF811178_my @ 0xFF811178 - 0xFF811224, length=44
 204 void __attribute__((naked,noinline)) sub_FF811178_my() {
 205 asm volatile (
 206 "    STR     LR, [SP, #-4]! \n"
 207 "    SUB     SP, SP, #0x74 \n"
 208 "    MOV     R0, SP \n"
 209 "    MOV     R1, #0x74 \n"
 210 "    BL      sub_FFB36884 \n"
 211 "    MOV     R0, #0x53000 \n"
 212 "    STR     R0, [SP, #4] \n"
 213 
 214 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 215 "    LDR     R0, =0x13DD20 \n"
 216 #else
 217 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 218 "    LDR     R0, [R0]\n"      //
 219 #endif
 220 
 221 "    LDR     R2, =0x2F9C00 \n"
 222 "    LDR     R1, =0x2F24A8 \n"
 223 "    STR     R0, [SP, #8] \n"
 224 "    SUB     R0, R1, R0 \n"
 225 "    ADD     R3, SP, #0xC \n"
 226 "    STR     R2, [SP] \n"
 227 "    STMIA   R3, {R0-R2} \n"
 228 "    MOV     R0, #0x22 \n"
 229 "    STR     R0, [SP, #0x18] \n"
 230 "    MOV     R0, #0x68 \n"
 231 "    STR     R0, [SP, #0x1C] \n"
 232 "    LDR     R0, =0x19B \n"
 233 "    LDR     R1, =sub_FF815E34_my \n"  // --> Patched. Old value = 0xFF815E34.
 234 "    STR     R0, [SP, #0x20] \n"
 235 "    MOV     R0, #0x96 \n"
 236 "    STR     R0, [SP, #0x24] \n"
 237 "    MOV     R0, #0x78 \n"
 238 "    STR     R0, [SP, #0x28] \n"
 239 "    MOV     R0, #0x64 \n"
 240 "    STR     R0, [SP, #0x2C] \n"
 241 "    MOV     R0, #0 \n"
 242 "    STR     R0, [SP, #0x30] \n"
 243 "    STR     R0, [SP, #0x34] \n"
 244 "    MOV     R0, #0x10 \n"
 245 "    STR     R0, [SP, #0x5C] \n"
 246 "    MOV     R0, #0x800 \n"
 247 "    STR     R0, [SP, #0x60] \n"
 248 "    MOV     R0, #0xA0 \n"
 249 "    STR     R0, [SP, #0x64] \n"
 250 "    MOV     R0, #0x280 \n"
 251 "    STR     R0, [SP, #0x68] \n"
 252 "    MOV     R0, SP \n"
 253 "    MOV     R2, #0 \n"
 254 "    BL      sub_FF8133E4 \n"
 255 "    ADD     SP, SP, #0x74 \n"
 256 "    LDR     PC, [SP], #4 \n"
 257 );
 258 }
 259 
 260 /*************************************************************/
 261 //** sub_FF815E34_my @ 0xFF815E34 - 0xFF815EA8, length=30
 262 void __attribute__((naked,noinline)) sub_FF815E34_my() {
 263 asm volatile (
 264 "    STMFD   SP!, {R4,LR} \n"
 265 "    BL      sub_FF810B08 \n"
 266 "    BL      sub_FF81A148 \n"
 267 "    CMP     R0, #0 \n"
 268 "    LDRLT   R0, =0xFF815F48 /*'dmSetup'*/ \n"
 269 "    BLLT    _err_init_task \n"
 270 "    BL      sub_FF815A70 \n"
 271 "    CMP     R0, #0 \n"
 272 "    LDRLT   R0, =0xFF815F50 /*'termDriverInit'*/ \n"
 273 "    BLLT    _err_init_task \n"
 274 "    LDR     R0, =0xFF815F60 /*'/_term'*/ \n"
 275 "    BL      sub_FF815B58 \n"
 276 "    CMP     R0, #0 \n"
 277 "    LDRLT   R0, =0xFF815F68 /*'termDeviceCreate'*/ \n"
 278 "    BLLT    _err_init_task \n"
 279 "    LDR     R0, =0xFF815F60 /*'/_term'*/ \n"
 280 "    BL      sub_FF813BE0 \n"
 281 "    CMP     R0, #0 \n"
 282 "    LDRLT   R0, =0xFF815F7C /*'stdioSetup'*/ \n"
 283 "    BLLT    _err_init_task \n"
 284 "    BL      sub_FF819B5C \n"
 285 "    CMP     R0, #0 \n"
 286 "    LDRLT   R0, =0xFF815F88 /*'stdlibSetup'*/ \n"
 287 "    BLLT    _err_init_task \n"
 288 "    BL      sub_FF81165C \n"
 289 "    CMP     R0, #0 \n"
 290 "    LDRLT   R0, =0xFF815F94 /*'armlib_setup'*/ \n"
 291 "    BLLT    _err_init_task \n"
 292 "    LDMFD   SP!, {R4,LR} \n"
 293 "    B       taskcreate_Startup_my \n"  // --> Patched. Old value = 0xFF81F868.
 294 );
 295 }
 296 
 297 /*************************************************************/
 298 //** taskcreate_Startup_my @ 0xFF81F868 - 0xFF81F8DC, length=30
 299 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 300 asm volatile (
 301 "    STMFD   SP!, {R3,LR} \n"
 302 //"  BL      _sub_FF85E710 \n"  // --> Nullsub call removed.
 303 "    BL      sub_FF83A634 \n"
 304 "    CMP     R0, #0 \n"
 305 "    BNE     loc_FF81F8A0 \n"
 306 "    BL      sub_FF85E6F4 \n"
 307 "    CMP     R0, #0 \n"
 308 "    BNE     loc_FF81F8A0 \n"
 309 "    BL      sub_FF832894 \n"
 310 "    LDR     R1, =0xC0220000 \n"
 311 "    MOV     R0, #0x44 \n"
 312 "    STR     R0, [R1, #0x1C] \n"
 313 "    BL      sub_FF832A80 \n"
 314 
 315 "loc_FF81F89C:\n"
 316 "    B       loc_FF81F89C \n"
 317 
 318 "loc_FF81F8A0:\n"
 319 //"  BL      _sub_FF85E718 \n"  // Removed for correct power-on
 320 //"  BL      _sub_FF85E714 \n"  // --> Nullsub call removed.
 321 "    BL      sub_FF8388E4 \n"
 322 "    LDR     R1, =0x34E000 \n"
 323 "    MOV     R0, #0 \n"
 324 "    BL      sub_FF838D2C \n"
 325 "    BL      sub_FF838AD8 \n"
 326 "    MOV     R3, #0 \n"
 327 "    STR     R3, [SP] \n"
 328 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF81F804.
 329 "    MOV     R2, #0 \n"
 330 "    MOV     R1, #0x19 \n"
 331 "    LDR     R0, =0xFF81F8E8 /*'Startup'*/ \n"
 332 "    BL      _CreateTask \n"
 333 "    MOV     R0, #0 \n"
 334 "    LDMFD   SP!, {R12,PC} \n"
 335 );
 336 }
 337 
 338 /*************************************************************/
 339 //** task_Startup_my @ 0xFF81F804 - 0xFF81F864, length=25
 340 void __attribute__((naked,noinline)) task_Startup_my() {
 341 asm volatile (
 342 "    STMFD   SP!, {R4,LR} \n"
 343 "    BL      sub_FF816490 \n"
 344 "    BL      sub_FF8342B4 \n"
 345 "    BL      sub_FF832508 \n"
 346 //"  BL      _sub_FF85F2F0 \n"  // --> Nullsub call removed.
 347 "    BL      sub_FF83A858 \n"
 348 //"  BL      _sub_FF83A708 \n"  // start diskboot.bin
 349 "    BL      sub_FF8970DC \n"
 350 "    BL      sub_FF83135C \n"
 351 "    BL      sub_FF83A888 \n"
 352 "    BL      sub_FF838088 \n"
 353 "    BL      sub_FF83AA00 \n"
 354 
 355 "    BL      CreateTask_spytask\n"  // added
 356 
 357 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFF8330BC.
 358 "    BL      sub_FF835F00 \n"
 359 "    BL      sub_FF83AA18 \n"
 360 //"  BL      _sub_FF830694 \n"  // --> Nullsub call removed.
 361 "    BL      sub_FF831EAC \n"
 362 "    BL      sub_FF83A40C \n"
 363 "    BL      sub_FF8324BC \n"
 364 "    BL      sub_FF831DC8 \n"
 365 "    BL      sub_FF831390 \n"
 366 "    BL      sub_FF83B670 \n"
 367 "    BL      sub_FF831DA0 \n"
 368 "    LDMFD   SP!, {R4,LR} \n"
 369 "    B       sub_FF8165B0 \n"
 370 );
 371 }
 372 
 373 /*************************************************************/
 374 //** taskcreatePhySw_my @ 0xFF8330BC - 0xFF8330DC, length=9
 375 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 376 asm volatile (
 377 "    STMFD   SP!, {R3-R5,LR} \n"
 378 "    LDR     R4, =0x1C38 \n"
 379 "    LDR     R0, [R4, #0x10] \n"
 380 "    CMP     R0, #0 \n"
 381 "    BNE     sub_FF8330F0 \n"
 382 "    MOV     R3, #0 \n"
 383 "    STR     R3, [SP] \n"
 384 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF833088.
 385 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw
 386 "    LDR     PC, =0xFF8330E0 \n"  // Continue in firmware
 387 );
 388 }
 389 
 390 /*************************************************************/
 391 //** init_file_modules_task @ 0xFF89A8CC - 0xFF89A900, length=14
 392 void __attribute__((naked,noinline)) init_file_modules_task() {
 393 asm volatile (
 394 "    STMFD   SP!, {R4-R6,LR} \n"
 395 "    BL      sub_FF88FB5C \n"
 396 "    LDR     R5, =0x5006 \n"
 397 "    MOVS    R4, R0 \n"
 398 "    MOVNE   R1, #0 \n"
 399 "    MOVNE   R0, R5 \n"
 400 "    BLNE    _PostLogicalEventToUI \n"
 401 "    BL      sub_FF88FB88_my \n"  // --> Patched. Old value = 0xFF88FB88.
 402 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 403 "    CMP     R4, #0 \n"
 404 "    MOVEQ   R0, R5 \n"
 405 "    LDMEQFD SP!, {R4-R6,LR} \n"
 406 "    MOVEQ   R1, #0 \n"
 407 "    BEQ     _PostLogicalEventToUI \n"
 408 "    LDMFD   SP!, {R4-R6,PC} \n"
 409 );
 410 }
 411 
 412 /*************************************************************/
 413 //** sub_FF88FB88_my @ 0xFF88FB88 - 0xFF88FB90, length=3
 414 void __attribute__((naked,noinline)) sub_FF88FB88_my() {
 415 asm volatile (
 416 "    STMFD   SP!, {R4,LR} \n"
 417 "    MOV     R0, #3 \n"
 418 "    BL      sub_FF86EDF4_my \n"  // --> Patched. Old value = 0xFF86EDF4.
 419 "    LDR     PC, =0xFF88FB94 \n"  // Continue in firmware
 420 );
 421 }
 422 
 423 /*************************************************************/
 424 //** sub_FF86EDF4_my @ 0xFF86EDF4 - 0xFF86EE48, length=22
 425 void __attribute__((naked,noinline)) sub_FF86EDF4_my() {
 426 asm volatile (
 427 "    STMFD   SP!, {R4-R8,LR} \n"
 428 "    MOV     R8, R0 \n"
 429 "    BL      sub_FF86ED74 \n"
 430 "    LDR     R1, =0x37260 \n"
 431 "    MOV     R6, R0 \n"
 432 "    ADD     R4, R1, R0, LSL#7 \n"
 433 "    LDR     R0, [R4, #0x6C] \n"
 434 "    CMP     R0, #4 \n"
 435 "    LDREQ   R1, =0x804 \n"
 436 "    LDREQ   R0, =0xFF86E8C0 /*'Mounter.c'*/ \n"
 437 "    BLEQ    _DebugAssert \n"
 438 "    MOV     R1, R8 \n"
 439 "    MOV     R0, R6 \n"
 440 "    BL      sub_FF86E614 \n"
 441 "    LDR     R0, [R4, #0x38] \n"
 442 "    BL      sub_FF86F410 \n"
 443 "    CMP     R0, #0 \n"
 444 "    STREQ   R0, [R4, #0x6C] \n"
 445 "    MOV     R0, R6 \n"
 446 "    BL      sub_FF86E6A4 \n"
 447 "    MOV     R0, R6 \n"
 448 "    BL      sub_FF86EA28_my \n"  // --> Patched. Old value = 0xFF86EA28.
 449 "    LDR     PC, =0xFF86EE4C \n"  // Continue in firmware
 450 );
 451 }
 452 
 453 /*************************************************************/
 454 //** sub_FF86EA28_my @ 0xFF86EA28 - 0xFF86EA50, length=11
 455 void __attribute__((naked,noinline)) sub_FF86EA28_my() {
 456 asm volatile (
 457 "    STMFD   SP!, {R4-R6,LR} \n"
 458 "    MOV     R5, R0 \n"
 459 "    LDR     R0, =0x37260 \n"
 460 "    ADD     R4, R0, R5, LSL#7 \n"
 461 "    LDR     R0, [R4, #0x6C] \n"
 462 "    TST     R0, #2 \n"
 463 "    MOVNE   R0, #1 \n"
 464 "    LDMNEFD SP!, {R4-R6,PC} \n"
 465 "    LDR     R0, [R4, #0x38] \n"
 466 "    MOV     R1, R5 \n"
 467 "    BL      sub_FF86E724_my \n"  // --> Patched. Old value = 0xFF86E724.
 468 "    LDR     PC, =0xFF86EA54 \n"  // Continue in firmware
 469 );
 470 }
 471 
 472 /*************************************************************/
 473 //** sub_FF86E724_my @ 0xFF86E724 - 0xFF86E894, length=93
 474 void __attribute__((naked,noinline)) sub_FF86E724_my() {
 475 asm volatile (
 476 "    STMFD   SP!, {R4-R10,LR} \n"
 477 "    MOV     R9, R0 \n"
 478 "    LDR     R0, =0x37260 \n"
 479 "    MOV     R8, #0 \n"
 480 "    ADD     R5, R0, R1, LSL#7 \n"
 481 "    LDR     R0, [R5, #0x3C] \n"
 482 "    MOV     R7, #0 \n"
 483 "    CMP     R0, #7 \n"
 484 "    MOV     R6, #0 \n"
 485 "    ADDLS   PC, PC, R0, LSL#2 \n"
 486 "    B       loc_FF86E87C \n"
 487 "    B       loc_FF86E788 \n"
 488 "    B       loc_FF86E770 \n"
 489 "    B       loc_FF86E770 \n"
 490 "    B       loc_FF86E770 \n"
 491 "    B       loc_FF86E770 \n"
 492 "    B       loc_FF86E874 \n"
 493 "    B       loc_FF86E770 \n"
 494 "    B       loc_FF86E770 \n"
 495 
 496 "loc_FF86E770:\n"
 497 "    MOV     R2, #0 \n"
 498 "    MOV     R1, #0x200 \n"
 499 "    MOV     R0, #2 \n"
 500 "    BL      sub_FF889BD0 \n"
 501 "    MOVS    R4, R0 \n"
 502 "    BNE     loc_FF86E790 \n"
 503 
 504 "loc_FF86E788:\n"
 505 "    MOV     R0, #0 \n"
 506 "    LDMFD   SP!, {R4-R10,PC} \n"
 507 
 508 "loc_FF86E790:\n"
 509 "    LDR     R12, [R5, #0x50] \n"
 510 "    MOV     R3, R4 \n"
 511 "    MOV     R2, #1 \n"
 512 "    MOV     R1, #0 \n"
 513 "    MOV     R0, R9 \n"
 514 "    BLX     R12 \n"
 515 "    CMP     R0, #1 \n"
 516 "    BNE     loc_FF86E7BC \n"
 517 "    MOV     R0, #2 \n"
 518 "    BL      sub_FF889D1C \n"
 519 "    B       loc_FF86E788 \n"
 520 
 521 "loc_FF86E7BC:\n"
 522 "    LDR     R1, [R5, #0x64] \n"
 523 "    MOV     R0, R9 \n"
 524 "    BLX     R1 \n"
 525 
 526 "    MOV     R1, R4\n"              //  pointer to MBR in R1
 527 "    BL      mbr_read_dryos\n"      //  total sectors count in R0 before and after call
 528 
 529 // Start of DataGhost's FAT32 autodetection code
 530 // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage
 531 // According to the code below, we can use R1, R2, R3 and R12.
 532 // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing
 533 // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :)
 534 "    MOV     R12, R4\n"             // Copy the MBR start address so we have something to work with
 535 "    MOV     LR, R4\n"              // Save old offset for MBR signature
 536 "    MOV     R1, #1\n"              // Note the current partition number
 537 "    B       dg_sd_fat32_enter\n"   // We actually need to check the first partition as well, no increments yet!
 538 "dg_sd_fat32:\n"
 539 "    CMP     R1, #4\n"              // Did we already see the 4th partition?
 540 "    BEQ     dg_sd_fat32_end\n"     // Yes, break. We didn't find anything, so don't change anything.
 541 "    ADD     R12, R12, #0x10\n"     // Second partition
 542 "    ADD     R1, R1, #1\n"          // Second partition for the loop
 543 "dg_sd_fat32_enter:\n"
 544 "    LDRB    R2, [R12, #0x1BE]\n"   // Partition status
 545 "    LDRB    R3, [R12, #0x1C2]\n"   // Partition type (FAT32 = 0xB)
 546 "    CMP     R3, #0xB\n"            // Is this a FAT32 partition?
 547 "    CMPNE   R3, #0xC\n"            // Not 0xB, is it 0xC (FAT32 LBA) then?
 548 "    CMPNE   R3, #0x7\n"            // exFat?
 549 "    BNE     dg_sd_fat32\n"         // No, it isn't. Loop again.
 550 "    CMP     R2, #0x00\n"           // It is, check the validity of the partition type
 551 "    CMPNE   R2, #0x80\n"
 552 "    BNE     dg_sd_fat32\n"         // Invalid, go to next partition
 553                                     // This partition is valid, it's the first one, bingo!
 554 "    MOV     R4, R12\n"             // Move the new MBR offset for the partition detection.
 555 
 556 "dg_sd_fat32_end:\n"
 557 // End of DataGhost's FAT32 autodetection code
 558 
 559 "    LDRB    R1, [R4, #0x1C9] \n"
 560 "    LDRB    R3, [R4, #0x1C8] \n"
 561 "    LDRB    R12, [R4, #0x1CC] \n"
 562 "    MOV     R1, R1, LSL#24 \n"
 563 "    ORR     R1, R1, R3, LSL#16 \n"
 564 "    LDRB    R3, [R4, #0x1C7] \n"
 565 "    LDRB    R2, [R4, #0x1BE] \n"
 566 //"  LDRB    LR, [R4, #0x1FF] \n"  // replaced below
 567 "    ORR     R1, R1, R3, LSL#8 \n"
 568 "    LDRB    R3, [R4, #0x1C6] \n"
 569 "    CMP     R2, #0 \n"
 570 "    CMPNE   R2, #0x80 \n"
 571 "    ORR     R1, R1, R3 \n"
 572 "    LDRB    R3, [R4, #0x1CD] \n"
 573 "    MOV     R3, R3, LSL#24 \n"
 574 "    ORR     R3, R3, R12, LSL#16 \n"
 575 "    LDRB    R12, [R4, #0x1CB] \n"
 576 "    ORR     R3, R3, R12, LSL#8 \n"
 577 "    LDRB    R12, [R4, #0x1CA] \n"
 578 "    ORR     R3, R3, R12 \n"
 579 //"  LDRB    R12, [R4, #0x1FE] \n"  // replaced below
 580 "    LDRB    R12, [LR,#0x1FE]\n"    // replace instructions above - First MBR signature byte (0x55), LR is original offset.
 581 "    LDRB    LR, [LR,#0x1FF]\n"     // replace instructions above - Last MBR signature byte (0xAA), LR is original offset.
 582 "    BNE     loc_FF86E848 \n"
 583 "    CMP     R0, R1 \n"
 584 "    BCC     loc_FF86E848 \n"
 585 "    ADD     R2, R1, R3 \n"
 586 "    CMP     R2, R0 \n"
 587 "    CMPLS   R12, #0x55 \n"
 588 "    CMPEQ   LR, #0xAA \n"
 589 "    MOVEQ   R7, R1 \n"
 590 "    MOVEQ   R6, R3 \n"
 591 "    MOVEQ   R4, #1 \n"
 592 "    BEQ     loc_FF86E84C \n"
 593 
 594 "loc_FF86E848:\n"
 595 "    MOV     R4, R8 \n"
 596 
 597 "loc_FF86E84C:\n"
 598 "    MOV     R0, #2 \n"
 599 "    BL      sub_FF889D1C \n"
 600 "    CMP     R4, #0 \n"
 601 "    BNE     loc_FF86E888 \n"
 602 "    LDR     R1, [R5, #0x64] \n"
 603 "    MOV     R7, #0 \n"
 604 "    MOV     R0, R9 \n"
 605 "    BLX     R1 \n"
 606 "    MOV     R6, R0 \n"
 607 "    B       loc_FF86E888 \n"
 608 
 609 "loc_FF86E874:\n"
 610 "    MOV     R6, #0x40 \n"
 611 "    B       loc_FF86E888 \n"
 612 
 613 "loc_FF86E87C:\n"
 614 "    LDR     R1, =0x568 \n"
 615 "    LDR     R0, =0xFF86E8C0 /*'Mounter.c'*/ \n"
 616 "    BL      _DebugAssert \n"
 617 
 618 "loc_FF86E888:\n"
 619 "    STR     R7, [R5, #0x44]! \n"
 620 "    STMIB   R5, {R6,R8} \n"
 621 "    MOV     R0, #1 \n"
 622 "    LDMFD   SP!, {R4-R10,PC} \n"
 623 );
 624 }
 625 
 626 /*************************************************************/
 627 //** JogDial_task_my @ 0xFF85F3CC - 0xFF85F784, length=239
 628 void __attribute__((naked,noinline)) JogDial_task_my() {
 629 asm volatile (
 630 "    STMFD   SP!, {R4-R11,LR} \n"
 631 "    SUB     SP, SP, #0x24 \n"
 632 "    ADD     R0, SP, #4 \n"
 633 "    BL      sub_FF839094 /*__GetSystemTime*/ \n"
 634 "    BL      sub_FF85F7DC \n"
 635 "    LDR     R1, =0x2578 \n"
 636 "    MOV     R0, #0 \n"
 637 
 638 // Save pointer for kbd.c routine
 639 "    LDR     R12, =jog_position \n"
 640 "    STR     R3, [R12] \n"
 641 
 642 "    ADD     R3, SP, #0x18 \n"
 643 "    ADD     R12, SP, #0x1C \n"
 644 "    ADD     R2, SP, #0x10 \n"
 645 "    ADD     R5, SP, #0x14 \n"
 646 "    MOV     R6, #0 \n"
 647 
 648 "loc_FF85F3FC:\n"
 649 "    ADD     R12, SP, #0x1C \n"
 650 "    ADD     LR, R12, R0, LSL#1 \n"
 651 "    ADD     R3, SP, #0x18 \n"
 652 "    STRH    R6, [LR] \n"
 653 "    ADD     LR, R3, R0, LSL#1 \n"
 654 "    ADD     R5, SP, #0x14 \n"
 655 "    STRH    R6, [LR] \n"
 656 "    ADD     R2, SP, #0x10 \n"
 657 "    STR     R6, [R5, R0, LSL#2] \n"
 658 "    STR     R6, [R2, R0, LSL#2] \n"
 659 "    ADD     R0, R0, #1 \n"
 660 "    CMP     R0, #1 \n"
 661 "    BLT     loc_FF85F3FC \n"
 662 
 663 "loc_FF85F430:\n"
 664 "    LDR     R0, =0x2578 \n"
 665 "    MOV     R2, #0 \n"
 666 "    LDR     R0, [R0, #0xC] \n"
 667 "    ADD     R1, SP, #8 \n"
 668 "    BL      sub_FF838318 /*_ReceiveMessageQueue*/ \n"
 669 "    TST     R0, #1 \n"
 670 "    LDRNE   R1, =0x226 \n"
 671 "    LDRNE   R0, =0xFF85F70C /*'JogDial.c'*/ \n"
 672 "    BLNE    _DebugAssert \n"
 673 "    LDR     R0, [SP, #8] \n"
 674 "    AND     R4, R0, #0xFF \n"
 675 "    AND     R0, R0, #0xFF00 \n"
 676 "    CMP     R0, #0x100 \n"
 677 "    BEQ     loc_FF85F4B4 \n"
 678 "    CMP     R0, #0x200 \n"
 679 "    BEQ     loc_FF85F4F0 \n"
 680 "    CMP     R0, #0x300 \n"
 681 "    BEQ     loc_FF85F754 \n"
 682 "    CMP     R0, #0x400 \n"
 683 "    BNE     loc_FF85F430 \n"
 684 "    CMP     R4, #0 \n"
 685 "    LDRNE   R1, =0x2CA \n"
 686 "    LDRNE   R0, =0xFF85F70C /*'JogDial.c'*/ \n"
 687 "    BLNE    _DebugAssert \n"
 688 "    LDR     R2, =0xFFB44C5C \n"
 689 "    ADD     R0, R4, R4, LSL#2 \n"
 690 "    LDR     R1, [R2, R0, LSL#2] \n"
 691 "    STR     R6, [R1] \n"
 692 "    ADD     R0, R2, R0, LSL#2 \n"
 693 "    LDR     R0, [R0, #8] \n"
 694 "    MOV     R1, #1 \n"
 695 
 696 "loc_FF85F4AC:\n"
 697 "    STR     R1, [R0] \n"
 698 "    B       loc_FF85F430 \n"
 699 
 700 "loc_FF85F4B4:\n"
 701 //------------------  added code ---------------------
 702 "labelA:\n"
 703 "    LDR     R0, =jogdial_stopped\n"
 704 "    LDR     R0, [R0]\n"
 705 "    CMP     R0, #1\n"
 706 "    BNE     labelB\n"
 707 "    MOV     R0, #40\n"
 708 "    BL      _SleepTask\n"
 709 "    B       labelA\n"
 710 "labelB:\n"
 711 //------------------  original code ------------------
 712 "    LDR     R5, =0x258C \n"
 713 "    LDR     R0, [R5, R4, LSL#2] \n"
 714 "    BL      sub_FF8392B0 /*_CancelTimer*/ \n"
 715 "    LDR     R2, =0xFF85F358 \n"
 716 "    MOV     R1, R2 \n"
 717 "    ORR     R3, R4, #0x200 \n"
 718 "    MOV     R0, #0x28 \n"
 719 "    BL      sub_FF8391CC /*_SetTimerAfter*/ \n"
 720 "    TST     R0, #1 \n"
 721 "    ADD     R1, SP, #0x10 \n"
 722 "    CMPNE   R0, #0x15 \n"
 723 "    STR     R0, [R1, R4, LSL#2] \n"
 724 "    BEQ     loc_FF85F430 \n"
 725 "    LDR     R1, =0x23B \n"
 726 "    B       loc_FF85F6FC \n"
 727 
 728 "loc_FF85F4F0:\n"
 729 "    LDR     R0, =0xFFB44C5C \n"
 730 "    ADD     R7, R4, R4, LSL#2 \n"
 731 "    ADD     R8, R0, R7, LSL#2 \n"
 732 "    LDR     R0, [R8, #4] \n"
 733 "    LDR     R0, [R0] \n"
 734 "    MOV     R2, R0, ASR#16 \n"
 735 "    ADD     R0, SP, #0x1C \n"
 736 "    ADD     R9, R0, R4, LSL#1 \n"
 737 "    ADD     R0, SP, #0x18 \n"
 738 "    ADD     R10, R0, R4, LSL#1 \n"
 739 "    STRH    R2, [R9] \n"
 740 "    LDRSH   R3, [R10] \n"
 741 "    SUB     R0, R2, R3 \n"
 742 "    CMP     R0, #0 \n"
 743 "    BEQ     loc_FF85F6AC \n"
 744 "    MOV     R1, R0 \n"
 745 "    RSBLT   R0, R0, #0 \n"
 746 "    MOVLE   R5, #0 \n"
 747 "    MOVGT   R5, #1 \n"
 748 "    CMP     R0, #0xFF \n"
 749 "    BLS     loc_FF85F56C \n"
 750 "    CMP     R1, #0 \n"
 751 "    RSBLE   R0, R3, #0xFF \n"
 752 "    ADDLE   R0, R0, #0x7F00 \n"
 753 "    ADDLE   R0, R0, R2 \n"
 754 "    RSBGT   R0, R2, #0xFF \n"
 755 "    ADDGT   R0, R0, #0x7F00 \n"
 756 "    ADDGT   R0, R0, R3 \n"
 757 "    ADD     R0, R0, #0x8000 \n"
 758 "    ADD     R0, R0, #1 \n"
 759 "    EOR     R5, R5, #1 \n"
 760 
 761 "loc_FF85F56C:\n"
 762 "    STR     R0, [SP, #0xC] \n"
 763 "    MOV     R0, SP \n"
 764 "    BL      sub_FF839094 /*__GetSystemTime*/ \n"
 765 "    LDR     R0, [SP, #4] \n"
 766 "    LDR     R1, [SP] \n"
 767 "    LDR     R2, [SP, #0xC] \n"
 768 "    SUB     R0, R1, R0 \n"
 769 "    CMP     R2, #1 \n"
 770 "    BNE     loc_FF85F5AC \n"
 771 "    LDR     R2, =0x2578 \n"
 772 "    LDR     R2, [R2] \n"
 773 "    CMP     R0, R2 \n"
 774 "    STRHI   R1, [SP, #4] \n"
 775 "    LDRHIH  R0, [R9] \n"
 776 "    STRHIH  R0, [R10] \n"
 777 "    BHI     loc_FF85F73C \n"
 778 
 779 "loc_FF85F5AC:\n"
 780 "    ADD     R0, SP, #0x14 \n"
 781 "    LDR     R0, [R0, R4, LSL#2] \n"
 782 "    CMP     R0, #0 \n"
 783 "    BEQ     loc_FF85F60C \n"
 784 "    LDR     R1, =0xFFB44C54 \n"
 785 "    ADD     R1, R1, R4, LSL#3 \n"
 786 "    LDR     R1, [R1, R5, LSL#2] \n"
 787 "    CMP     R1, R0 \n"
 788 "    BEQ     loc_FF85F62C \n"
 789 "    LDR     R1, =0xFFB44C70 \n"
 790 "    ADD     R0, R4, R4, LSL#1 \n"
 791 "    ADD     R11, R1, R0, LSL#2 \n"
 792 "    STR     R0, [SP, #0x20] \n"
 793 "    LDRB    R0, [R11, #9] \n"
 794 "    CMP     R0, #1 \n"
 795 "    LDREQ   R0, [R11, #4] \n"
 796 "    BLEQ    sub_FF896B84 \n"
 797 "    LDRB    R1, [R11, #8] \n"
 798 "    LDR     R0, =0xFFB44C70 \n"
 799 "    CMP     R1, #1 \n"
 800 "    BNE     loc_FF85F62C \n"
 801 "    LDR     R1, [SP, #0x20] \n"
 802 "    LDR     R0, [R0, R1, LSL#2] \n"
 803 "    B       loc_FF85F628 \n"
 804 
 805 "loc_FF85F60C:\n"
 806 "    LDR     R2, =0xFFB44C70 \n"
 807 "    ADD     R0, R4, R4, LSL#1 \n"
 808 "    ADD     R1, R2, R0, LSL#2 \n"
 809 "    LDRB    R1, [R1, #8] \n"
 810 "    CMP     R1, #1 \n"
 811 "    BNE     loc_FF85F62C \n"
 812 "    LDR     R0, [R2, R0, LSL#2] \n"
 813 
 814 "loc_FF85F628:\n"
 815 "    BL      sub_FF896B84 \n"
 816 
 817 "loc_FF85F62C:\n"
 818 "    LDR     R0, =0xFFB44C54 \n"
 819 "    LDR     R1, [SP, #0xC] \n"
 820 "    ADD     R11, R0, R4, LSL#3 \n"
 821 "    LDR     R0, [R11, R5, LSL#2] \n"
 822 "    BL      sub_FF896AB4 \n"
 823 "    LDR     R0, [R11, R5, LSL#2] \n"
 824 "    ADD     R1, SP, #0x14 \n"
 825 "    STR     R0, [R1, R4, LSL#2] \n"
 826 "    LDRH    R0, [R9] \n"
 827 "    STRH    R0, [R10] \n"
 828 "    ADD     R0, SP, #4 \n"
 829 "    BL      sub_FF839094 /*__GetSystemTime*/ \n"
 830 "    LDR     R2, =0xFFB44C70 \n"
 831 "    ADD     R0, R4, R4, LSL#1 \n"
 832 "    ADD     R0, R2, R0, LSL#2 \n"
 833 "    LDRB    R0, [R0, #9] \n"
 834 "    CMP     R0, #1 \n"
 835 "    BNE     loc_FF85F6AC \n"
 836 "    LDR     R5, =0x258C \n"
 837 "    LDR     R0, [R5, R4, LSL#2] \n"
 838 "    BL      sub_FF8392B0 /*_CancelTimer*/ \n"
 839 "    LDR     R2, =0xFF85F364 \n"
 840 "    MOV     R1, R2 \n"
 841 "    ORR     R3, R4, #0x300 \n"
 842 "    MOV     R0, #0x1F4 \n"
 843 "    BL      sub_FF8391CC /*_SetTimerAfter*/ \n"
 844 "    TST     R0, #1 \n"
 845 "    CMPNE   R0, #0x15 \n"
 846 "    STR     R0, [R5, R4, LSL#2] \n"
 847 "    LDRNE   R0, =0xFF85F70C /*'JogDial.c'*/ \n"
 848 "    MOVNE   R1, #0x2A4 \n"
 849 "    BLNE    _DebugAssert \n"
 850 
 851 "loc_FF85F6AC:\n"
 852 "    LDR     R2, =0xFFB44C70 \n"
 853 "    ADD     R0, R4, R4, LSL#1 \n"
 854 "    ADD     R0, R2, R0, LSL#2 \n"
 855 "    LDRB    R0, [R0, #0xA] \n"
 856 "    CMP     R0, #1 \n"
 857 "    BNE     loc_FF85F73C \n"
 858 "    LDR     R0, =0x2578 \n"
 859 "    LDR     R0, [R0, #0x10] \n"
 860 "    CMP     R0, #0 \n"
 861 "    BEQ     loc_FF85F73C \n"
 862 "    LDR     R2, =0xFF85F358 \n"
 863 "    MOV     R1, R2 \n"
 864 "    ORR     R3, R4, #0x400 \n"
 865 "    BL      sub_FF8391CC /*_SetTimerAfter*/ \n"
 866 "    TST     R0, #1 \n"
 867 "    ADD     R1, SP, #0x10 \n"
 868 "    CMPNE   R0, #0x15 \n"
 869 "    STR     R0, [R1, R4, LSL#2] \n"
 870 "    BEQ     loc_FF85F430 \n"
 871 "    LDR     R1, =0x2AF \n"
 872 
 873 "loc_FF85F6FC:\n"
 874 "    LDR     R0, =0xFF85F70C /*'JogDial.c'*/ \n"
 875 "    BL      _DebugAssert \n"
 876 "    B       loc_FF85F430 \n"
 877 
 878 "loc_FF85F73C:\n"
 879 "    LDR     R0, =0xFFB44C5C \n"
 880 "    LDR     R0, [R0, R7, LSL#2] \n"
 881 "    STR     R6, [R0] \n"
 882 "    LDR     R0, [R8, #8] \n"
 883 "    MOV     R1, #1 \n"
 884 "    B       loc_FF85F4AC \n"
 885 
 886 "loc_FF85F754:\n"
 887 "    ADD     R5, SP, #0x14 \n"
 888 "    LDR     R0, [R5, R4, LSL#2] \n"
 889 "    CMP     R0, #0 \n"
 890 "    MOVEQ   R1, #0x2BC \n"
 891 "    LDREQ   R0, =0xFF85F70C /*'JogDial.c'*/ \n"
 892 "    BLEQ    _DebugAssert \n"
 893 "    LDR     R2, =0xFFB44C70 \n"
 894 "    ADD     R0, R4, R4, LSL#1 \n"
 895 "    ADD     R0, R2, R0, LSL#2 \n"
 896 "    LDR     R0, [R0, #4] \n"
 897 "    BL      sub_FF896B84 \n"
 898 "    STR     R6, [R5, R4, LSL#2] \n"
 899 "    B       loc_FF85F430 \n"
 900 );
 901 }

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