root/platform/sx30/sub/100p/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_FF811198_my
  6. sub_FF815EE0_my
  7. taskcreate_Startup_my
  8. task_Startup_my
  9. taskcreatePhySw_my
  10. init_file_modules_task
  11. sub_FF89A2C4_my
  12. sub_FF876E1C_my
  13. sub_FF876A44_my
  14. sub_FF876764_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_InitFileModules();
  19 extern void task_RotaryEncoder();
  20 extern void task_MovieRecord();
  21 extern void task_ExpDrv();
  22 extern void task_FileWrite();
  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_RotaryEncoder)             tcb->entry = (void*)JogDial_task_my;
  32         if(tcb->entry == (void*)task_MovieRecord)               tcb->entry = (void*)movie_record_task;
  33         if(tcb->entry == (void*)task_ExpDrv)                    tcb->entry = (void*)exp_drv_task;
  34     if(tcb->entry == (void*)task_FileWrite)         tcb->entry = (void*)filewritetask;
  35 }
  36 
  37 /*----------------------------------------------------------------------
  38         CreateTask --> core_spytask
  39 -----------------------------------------------------------------------*/
  40 void CreateTask_spytask()
  41 {
  42         _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);
  43 }
  44 
  45 //----------------------------------------------------------------------
  46 // Pointer to stack location where jogdial task records previous and current
  47 // jogdial positions
  48 short *jog_position;
  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, #0x35 \n"
  74 "    MCR     p15, 0, R0, c6, c2 \n"
  75 "    MOV     R0, #0x40000035 \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, =0xFFC90980 \n"
 134 "    LDR     R1, =0x1900 \n"
 135 "    LDR     R3, =0x108B8 \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, =0x18124C \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*)0x1938=(int)taskHook;
 159         *(int*)0x193C=(int)taskHook;    // need this for startup in Playback mode (otherwise init_file_modules_task doesn't hook properly)
 160     
 161         // replacement of sub_FF834740 for correct power-on.
 162         *(int*)(0x2574) = (*(int*)0xC0220128)&1 ? 0x200000 : 0x100000; 
 163 
 164 asm volatile (
 165 "    LDR     R0, =0xFF8103CC \n"
 166 "    MOV     R1, #0 \n"
 167 "    LDR     R3, =0xFF810404 \n"
 168 
 169 "loc_FF810360:\n"
 170 "    CMP     R0, R3 \n"
 171 "    LDRCC   R2, [R0], #4 \n"
 172 "    STRCC   R2, [R1], #4 \n"
 173 "    BCC     loc_FF810360 \n"
 174 "    LDR     R0, =0xFF810404 \n"
 175 "    MOV     R1, #0x4B0 \n"
 176 "    LDR     R3, =0xFF810618 \n"
 177 
 178 "loc_FF81037C:\n"
 179 "    CMP     R0, R3 \n"
 180 "    LDRCC   R2, [R0], #4 \n"
 181 "    STRCC   R2, [R1], #4 \n"
 182 "    BCC     loc_FF81037C \n"
 183 "    MOV     R0, #0xD2 \n"
 184 "    MSR     CPSR_cxsf, R0 \n"
 185 "    MOV     SP, #0x1000 \n"
 186 "    MOV     R0, #0xD3 \n"
 187 "    MSR     CPSR_cxsf, R0 \n"
 188 "    MOV     SP, #0x1000 \n"
 189 "    LDR     R0, =0x6C4 \n"
 190 "    LDR     R2, =0xEEEEEEEE \n"
 191 "    MOV     R3, #0x1000 \n"
 192 
 193 "loc_FF8103B0:\n"
 194 "    CMP     R0, R3 \n"
 195 "    STRCC   R2, [R0], #4 \n"
 196 "    BCC     loc_FF8103B0 \n"
 197 "    BL      sub_FF811198_my \n"  // --> Patched. Old value = 0xFF811198.
 198 );
 199 }
 200 
 201 /*************************************************************/
 202 //** sub_FF811198_my @ 0xFF811198 - 0xFF8111EC, length=22
 203 void __attribute__((naked,noinline)) sub_FF811198_my() {
 204 asm volatile (
 205 "    STR     LR, [SP, #-4]! \n"
 206 "    SUB     SP, SP, #0x74 \n"
 207 "    MOV     R0, SP \n"
 208 "    MOV     R1, #0x74 \n"
 209 "    BL      sub_FFB927A0 \n"
 210 "    MOV     R0, #0x53000 \n"
 211 "    STR     R0, [SP, #4] \n"
 212 
 213 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 214 "    LDR     R0, =0x18124C \n"
 215 #else
 216 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 217 "    LDR     R0, [R0]\n"      // 
 218 #endif
 219 
 220 "    LDR     R1, =0x379C00 \n"
 221 "    STR     R0, [SP, #8] \n"
 222 "    RSB     R0, R0, #0x1F80 \n"
 223 "    ADD     R0, R0, #0x370000 \n"
 224 "    STR     R0, [SP, #0xC] \n"
 225 "    LDR     R0, =0x371F80 \n"
 226 "    STR     R1, [SP] \n"
 227 "    STRD    R0, [SP, #0x10] \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_FF815EE0_my \n"  // --> Patched. Old value = 0xFF815EE0.
 234 "    LDR     PC, =0xFF8111F0 \n"  // Continue in firmware
 235 );
 236 }
 237 
 238 /*************************************************************/
 239 //** sub_FF815EE0_my @ 0xFF815EE0 - 0xFF815F54, length=30
 240 void __attribute__((naked,noinline)) sub_FF815EE0_my() {
 241 asm volatile (
 242 "    STMFD   SP!, {R4,LR} \n"
 243 "    BL      sub_FF810B20 \n"
 244 "    BL      sub_FF81A33C \n"
 245 "    CMP     R0, #0 \n"
 246 "    LDRLT   R0, =0xFF815FF4 /*'dmSetup'*/ \n"
 247 "    BLLT    _err_init_task \n"
 248 "    BL      sub_FF815B1C \n"
 249 "    CMP     R0, #0 \n"
 250 "    LDRLT   R0, =0xFF815FFC /*'termDriverInit'*/ \n"
 251 "    BLLT    _err_init_task \n"
 252 "    LDR     R0, =0xFF81600C /*'/_term'*/ \n"
 253 "    BL      sub_FF815C04 \n"
 254 "    CMP     R0, #0 \n"
 255 "    LDRLT   R0, =0xFF816014 /*'termDeviceCreate'*/ \n"
 256 "    BLLT    _err_init_task \n"
 257 "    LDR     R0, =0xFF81600C /*'/_term'*/ \n"
 258 "    BL      sub_FF813CA4 \n"
 259 "    CMP     R0, #0 \n"
 260 "    LDRLT   R0, =0xFF816028 /*'stdioSetup'*/ \n"
 261 "    BLLT    _err_init_task \n"
 262 "    BL      sub_FF819CC4 \n"
 263 "    CMP     R0, #0 \n"
 264 "    LDRLT   R0, =0xFF816034 /*'stdlibSetup'*/ \n"
 265 "    BLLT    _err_init_task \n"
 266 "    BL      sub_FF81167C \n"
 267 "    CMP     R0, #0 \n"
 268 "    LDRLT   R0, =0xFF816040 /*'armlib_setup'*/ \n"
 269 "    BLLT    _err_init_task \n"
 270 "    LDMFD   SP!, {R4,LR} \n"
 271 "    B       taskcreate_Startup_my \n"  // --> Patched. Old value = 0xFF81FB54.
 272 );
 273 }
 274 
 275 /*************************************************************/
 276 //** taskcreate_Startup_my @ 0xFF81FB54 - 0xFF81FBBC, length=27
 277 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 278 asm volatile (
 279 "    STMFD   SP!, {R3,LR} \n"
 280 //"  BL      _sub_FF86507C \n"  // --> Nullsub call removed.
 281 "    BL      sub_FF83C880 \n"
 282 "    CMP     R0, #0 \n"
 283 "    BNE     loc_FF81FB98 \n"
 284 "    BL      sub_FF836160 /*_IsNormalCameraMode_FW*/ \n"
 285 "    CMP     R0, #0 \n"
 286 "    BEQ     loc_FF81FB98 \n"
 287 "    BL      sub_FF865060 \n"
 288 "    CMP     R0, #0 \n"
 289 "    BNE     loc_FF81FB98 \n"
 290 "    BL      sub_FF833DDC \n"
 291 "    LDR     R1, =0xC0220000 \n"
 292 "    MOV     R0, #0x44 \n"
 293 "    STR     R0, [R1, #0x1C] \n"
 294 "    BL      sub_FF833FCC \n"
 295 
 296 "loc_FF81FB94:\n"
 297 "    B       loc_FF81FB94 \n"
 298 
 299 "loc_FF81FB98:\n"
 300 //"  BL      _sub_FF865084 \n"  // See begin of sub_FF810354_my()
 301 //"  BL      _sub_FF865080 \n"  // --> Nullsub call removed.
 302 "    BL      sub_FF83AA94 \n"
 303 "    LDR     R1, =0x3CE000 \n"
 304 "    MOV     R0, #0 \n"
 305 "    BL      sub_FF83AEDC \n"
 306 "    BL      sub_FF83AC88 \n"
 307 "    MOV     R3, #0 \n"
 308 "    STR     R3, [SP] \n"
 309 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF81FAF0.
 310 "    LDR     PC, =0xFF81FBC0 \n"  // Continue in firmware
 311 );
 312 }
 313 
 314 /*************************************************************/
 315 //** task_Startup_my @ 0xFF81FAF0 - 0xFF81FB20, length=13
 316 void __attribute__((naked,noinline)) task_Startup_my() {
 317 asm volatile (
 318 "    STMFD   SP!, {R4,LR} \n"
 319 "    BL      sub_FF816594 \n"
 320 "    BL      sub_FF835894 \n"
 321 "    BL      sub_FF8339A4 \n"
 322 //"  BL      _sub_FF865BC8 \n"  // --> Nullsub call removed.
 323 "    BL      sub_FF83CAB0 \n"
 324 //"  BL      _sub_FF83C958 \n"  // start diskboot.bin
 325 "    BL      sub_FF8A04CC \n"
 326 "    BL      sub_FF832474 \n"
 327 "    BL      sub_FF83CAE0 \n"
 328 "    BL      sub_FF83A238 \n"
 329 "    BL      sub_FF83CC58 \n"
 330 
 331 "    BL      CreateTask_spytask\n"  // added
 332 
 333 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFF83461C.
 334 "    LDR     PC, =0xFF81FB24 \n"  // Continue in firmware
 335 );
 336 }
 337 
 338 /*************************************************************/
 339 //** taskcreatePhySw_my @ 0xFF83461C - 0xFF83463C, length=9
 340 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 341 asm volatile (
 342 "    STMFD   SP!, {R3-R5,LR} \n"
 343 "    LDR     R4, =0x1C30 \n"
 344 "    LDR     R0, [R4, #0x10] \n"
 345 "    CMP     R0, #0 \n"
 346 "    BNE     sub_FF834650 \n"
 347 "    MOV     R3, #0 \n"
 348 "    STR     R3, [SP] \n"
 349 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF8345E8.
 350 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw
 351 "    LDR     PC, =0xFF834640 \n"  // Continue in firmware
 352 );
 353 }
 354 
 355 /*************************************************************/
 356 //** init_file_modules_task @ 0xFF8A3B50 - 0xFF8A3B6C, length=8
 357 void __attribute__((naked,noinline)) init_file_modules_task() {
 358 asm volatile (
 359 "    STMFD   SP!, {R4-R6,LR} \n"
 360 "    BL      sub_FF89A298 \n"
 361 "    LDR     R5, =0x5006 \n"
 362 "    MOVS    R4, R0 \n"
 363 "    MOVNE   R1, #0 \n"
 364 "    MOVNE   R0, R5 \n"
 365 "    BLNE    _PostLogicalEventToUI \n"
 366 "    BL      sub_FF89A2C4_my \n"  // --> Patched. Old value = 0xFF89A2C4.
 367 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 368 "    LDR     PC, =0xFF8A3B70 \n"  // Continue in firmware
 369 );
 370 }
 371 
 372 /*************************************************************/
 373 //** sub_FF89A2C4_my @ 0xFF89A2C4 - 0xFF89A2CC, length=3
 374 void __attribute__((naked,noinline)) sub_FF89A2C4_my() {
 375 asm volatile (
 376 "    STMFD   SP!, {R4,LR} \n"
 377 "    MOV     R0, #3 \n"
 378 "    BL      sub_FF876E1C_my \n"  // --> Patched. Old value = 0xFF876E1C.
 379 "    LDR     PC, =0xFF89A2D0 \n"  // Continue in firmware
 380 );
 381 }
 382 
 383 /*************************************************************/
 384 //** sub_FF876E1C_my @ 0xFF876E1C - 0xFF876E70, length=22
 385 void __attribute__((naked,noinline)) sub_FF876E1C_my() {
 386 asm volatile (
 387 "    STMFD   SP!, {R4-R8,LR} \n"
 388 "    MOV     R8, R0 \n"
 389 "    BL      sub_FF876D9C \n"
 390 "    LDR     R1, =0x3A738 \n"
 391 "    MOV     R6, R0 \n"
 392 "    ADD     R4, R1, R0, LSL#7 \n"
 393 "    LDR     R0, [R4, #0x6C] \n"
 394 "    CMP     R0, #4 \n"
 395 "    LDREQ   R1, =0x83F \n"
 396 "    LDREQ   R0, =0xFF8768DC /*'Mounter.c'*/ \n"
 397 "    BLEQ    _DebugAssert \n"
 398 "    MOV     R1, R8 \n"
 399 "    MOV     R0, R6 \n"
 400 "    BL      sub_FF876650 \n"
 401 "    LDR     R0, [R4, #0x38] \n"
 402 "    BL      sub_FF8774C0 \n"
 403 "    CMP     R0, #0 \n"
 404 "    STREQ   R0, [R4, #0x6C] \n"
 405 "    MOV     R0, R6 \n"
 406 "    BL      sub_FF8766E0 \n"
 407 "    MOV     R0, R6 \n"
 408 "    BL      sub_FF876A44_my \n"  // --> Patched. Old value = 0xFF876A44.
 409 "    LDR     PC, =0xFF876E74 \n"  // Continue in firmware
 410 );
 411 }
 412 
 413 /*************************************************************/
 414 //** sub_FF876A44_my @ 0xFF876A44 - 0xFF876A6C, length=11
 415 void __attribute__((naked,noinline)) sub_FF876A44_my() {
 416 asm volatile (
 417 "    STMFD   SP!, {R4-R6,LR} \n"
 418 "    MOV     R5, R0 \n"
 419 "    LDR     R0, =0x3A738 \n"
 420 "    ADD     R4, R0, R5, LSL#7 \n"
 421 "    LDR     R0, [R4, #0x6C] \n"
 422 "    TST     R0, #2 \n"
 423 "    MOVNE   R0, #1 \n"
 424 "    LDMNEFD SP!, {R4-R6,PC} \n"
 425 "    LDR     R0, [R4, #0x38] \n"
 426 "    MOV     R1, R5 \n"
 427 "    BL      sub_FF876764_my \n"  // --> Patched. Old value = 0xFF876764.
 428 "    LDR     PC, =0xFF876A70 \n"  // Continue in firmware
 429 );
 430 }
 431 
 432 /*************************************************************/
 433 //** sub_FF876764_my @ 0xFF876764 - 0xFF8768D4, length=93
 434 void __attribute__((naked,noinline)) sub_FF876764_my() {
 435 asm volatile (
 436 "    STMFD   SP!, {R4-R10,LR} \n"
 437 "    MOV     R9, R0 \n"
 438 "    LDR     R0, =0x3A738 \n"
 439 "    MOV     R8, #0 \n"
 440 "    ADD     R5, R0, R1, LSL#7 \n"
 441 "    LDR     R0, [R5, #0x3C] \n"
 442 "    MOV     R7, #0 \n"
 443 "    CMP     R0, #7 \n"
 444 "    MOV     R6, #0 \n"
 445 "    ADDLS   PC, PC, R0, LSL#2 \n"
 446 "    B       loc_FF8768BC \n"
 447 "    B       loc_FF8767C8 \n"
 448 "    B       loc_FF8767B0 \n"
 449 "    B       loc_FF8767B0 \n"
 450 "    B       loc_FF8767B0 \n"
 451 "    B       loc_FF8767B0 \n"
 452 "    B       loc_FF8768B4 \n"
 453 "    B       loc_FF8767B0 \n"
 454 "    B       loc_FF8767B0 \n"
 455 
 456 "loc_FF8767B0:\n"
 457 "    MOV     R2, #0 \n"
 458 "    MOV     R1, #0x200 \n"
 459 "    MOV     R0, #2 \n"
 460 "    BL      sub_FF894348 \n"
 461 "    MOVS    R4, R0 \n"
 462 "    BNE     loc_FF8767D0 \n"
 463 
 464 "loc_FF8767C8:\n"
 465 "    MOV     R0, #0 \n"
 466 "    LDMFD   SP!, {R4-R10,PC} \n"
 467 
 468 "loc_FF8767D0:\n"
 469 "    LDR     R12, [R5, #0x50] \n"
 470 "    MOV     R3, R4 \n"
 471 "    MOV     R2, #1 \n"
 472 "    MOV     R1, #0 \n"
 473 "    MOV     R0, R9 \n"
 474 "    BLX     R12 \n"
 475 "    CMP     R0, #1 \n"
 476 "    BNE     loc_FF8767FC \n"
 477 "    MOV     R0, #2 \n"
 478 "    BL      sub_FF894498 \n"
 479 "    B       loc_FF8767C8 \n"
 480 
 481 "loc_FF8767FC:\n"
 482 "    LDR     R1, [R5, #0x64] \n"
 483 "    MOV     R0, R9 \n"
 484 "    BLX     R1 \n"
 485 
 486 "    MOV     R1, R4\n"              //  pointer to MBR in R1
 487 "    BL      mbr_read_dryos\n"      //  total sectors count in R0 before and after call
 488 
 489 // Start of DataGhost's FAT32 autodetection code
 490 // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage
 491 // According to the code below, we can use R1, R2, R3 and R12.
 492 // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing
 493 // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :)
 494 "    MOV     R12, R4\n"             // Copy the MBR start address so we have something to work with
 495 "    MOV     LR, R4\n"              // Save old offset for MBR signature
 496 "    MOV     R1, #1\n"              // Note the current partition number
 497 "    B       dg_sd_fat32_enter\n"   // We actually need to check the first partition as well, no increments yet!
 498 "dg_sd_fat32:\n"
 499 "    CMP     R1, #4\n"              // Did we already see the 4th partition?
 500 "    BEQ     dg_sd_fat32_end\n"     // Yes, break. We didn't find anything, so don't change anything.
 501 "    ADD     R12, R12, #0x10\n"     // Second partition
 502 "    ADD     R1, R1, #1\n"          // Second partition for the loop
 503 "dg_sd_fat32_enter:\n"
 504 "    LDRB    R2, [R12, #0x1BE]\n"   // Partition status
 505 "    LDRB    R3, [R12, #0x1C2]\n"   // Partition type (FAT32 = 0xB)
 506 "    CMP     R3, #0xB\n"            // Is this a FAT32 partition?
 507 "    CMPNE   R3, #0xC\n"            // Not 0xB, is it 0xC (FAT32 LBA) then?
 508 "    CMPNE   R3, #0x7\n"            // exFat?
 509 "    BNE     dg_sd_fat32\n"         // No, it isn't. Loop again.
 510 "    CMP     R2, #0x00\n"           // It is, check the validity of the partition type
 511 "    CMPNE   R2, #0x80\n"
 512 "    BNE     dg_sd_fat32\n"         // Invalid, go to next partition
 513                                     // This partition is valid, it's the first one, bingo!
 514 "    MOV     R4, R12\n"             // Move the new MBR offset for the partition detection.
 515 
 516 "dg_sd_fat32_end:\n"
 517 // End of DataGhost's FAT32 autodetection code
 518 
 519 "    LDRB    R1, [R4, #0x1C9] \n"
 520 "    LDRB    R3, [R4, #0x1C8] \n"
 521 "    LDRB    R12, [R4, #0x1CC] \n"
 522 "    MOV     R1, R1, LSL#24 \n"
 523 "    ORR     R1, R1, R3, LSL#16 \n"
 524 "    LDRB    R3, [R4, #0x1C7] \n"
 525 "    LDRB    R2, [R4, #0x1BE] \n"
 526 //"  LDRB    LR, [R4, #0x1FF] \n"  // replaced below
 527 "    ORR     R1, R1, R3, LSL#8 \n"
 528 "    LDRB    R3, [R4, #0x1C6] \n"
 529 "    CMP     R2, #0 \n"
 530 "    CMPNE   R2, #0x80 \n"
 531 "    ORR     R1, R1, R3 \n"
 532 "    LDRB    R3, [R4, #0x1CD] \n"
 533 "    MOV     R3, R3, LSL#24 \n"
 534 "    ORR     R3, R3, R12, LSL#16 \n"
 535 "    LDRB    R12, [R4, #0x1CB] \n"
 536 "    ORR     R3, R3, R12, LSL#8 \n"
 537 "    LDRB    R12, [R4, #0x1CA] \n"
 538 "    ORR     R3, R3, R12 \n"
 539 //"  LDRB    R12, [R4, #0x1FE] \n"  // replaced below
 540 "    LDRB    R12, [LR,#0x1FE]\n"    // replace instructions above
 541 "    LDRB    LR, [LR,#0x1FF]\n"     // replace instructions above
 542 "    BNE     loc_FF876888 \n"
 543 "    CMP     R0, R1 \n"
 544 "    BCC     loc_FF876888 \n"
 545 "    ADD     R2, R1, R3 \n"
 546 "    CMP     R2, R0 \n"
 547 "    CMPLS   R12, #0x55 \n"
 548 "    CMPEQ   LR, #0xAA \n"
 549 "    MOVEQ   R7, R1 \n"
 550 "    MOVEQ   R6, R3 \n"
 551 "    MOVEQ   R4, #1 \n"
 552 "    BEQ     loc_FF87688C \n"
 553 
 554 "loc_FF876888:\n"
 555 "    MOV     R4, R8 \n"
 556 
 557 "loc_FF87688C:\n"
 558 "    MOV     R0, #2 \n"
 559 "    BL      sub_FF894498 \n"
 560 "    CMP     R4, #0 \n"
 561 "    BNE     loc_FF8768C8 \n"
 562 "    LDR     R1, [R5, #0x64] \n"
 563 "    MOV     R7, #0 \n"
 564 "    MOV     R0, R9 \n"
 565 "    BLX     R1 \n"
 566 "    MOV     R6, R0 \n"
 567 "    B       loc_FF8768C8 \n"
 568 
 569 "loc_FF8768B4:\n"
 570 "    MOV     R6, #0x40 \n"
 571 "    B       loc_FF8768C8 \n"
 572 
 573 "loc_FF8768BC:\n"
 574 "    LDR     R1, =0x597 \n"
 575 "    LDR     R0, =0xFF8768DC /*'Mounter.c'*/ \n"
 576 "    BL      _DebugAssert \n"
 577 
 578 "loc_FF8768C8:\n"
 579 "    STR     R7, [R5, #0x44]! \n"
 580 "    STMIB   R5, {R6,R8} \n"
 581 "    MOV     R0, #1 \n"
 582 "    LDMFD   SP!, {R4-R10,PC} \n"
 583 );
 584 }
 585 
 586 /*************************************************************/
 587 //** JogDial_task_my @ 0xFF865D08 - 0xFF866030, length=203
 588 void __attribute__((naked,noinline)) JogDial_task_my() {
 589 asm volatile (
 590 "    STMFD   SP!, {R4-R11,LR} \n"
 591 "    SUB     SP, SP, #0x1C \n"
 592 "    BL      sub_FF8660A0 \n"
 593 "    LDR     R1, =0x2588 \n"
 594 "    LDR     R6, =0xFFB97CF0 \n"
 595 "    MOV     R0, #0 \n"
 596 "    ADD     R3, SP, #0x10 \n"
 597 
 598 // Save pointer for kbd.c routine
 599 "    LDR     R12, =jog_position \n"
 600 "    STR     R3, [R12] \n"
 601 
 602 "    ADD     R12, SP, #0x14 \n"
 603 "    ADD     R10, SP, #8 \n"
 604 "    MOV     R2, #0 \n"
 605 "    ADD     R9, SP, #0xC \n"
 606 
 607 "loc_FF865D34:\n"
 608 "    ADD     R12, SP, #0x14 \n"
 609 "    ADD     LR, R12, R0, LSL#1 \n"
 610 "    MOV     R2, #0 \n"
 611 "    ADD     R3, SP, #0x10 \n"
 612 "    STRH    R2, [LR] \n"
 613 "    ADD     LR, R3, R0, LSL#1 \n"
 614 "    STRH    R2, [LR] \n"
 615 "    STR     R2, [R9, R0, LSL#2] \n"
 616 "    STR     R2, [R10, R0, LSL#2] \n"
 617 "    ADD     R0, R0, #1 \n"
 618 "    CMP     R0, #1 \n"
 619 "    BLT     loc_FF865D34 \n"
 620 
 621 "loc_FF865D64:\n"
 622 "    LDR     R0, =0x2588 \n"
 623 "    MOV     R2, #0 \n"
 624 "    LDR     R0, [R0, #8] \n"
 625 "    MOV     R1, SP \n"
 626 "    BL      sub_FF83A4C8 /*_ReceiveMessageQueue*/ \n"
 627 "    CMP     R0, #0 \n"
 628 "    LDRNE   R1, =0x262 \n"
 629 "    LDRNE   R0, =0xFF865FC4 /*'RotaryEncoder.c'*/ \n"
 630 "    BLNE    _DebugAssert \n"
 631 "    LDR     R0, [SP] \n"
 632 "    AND     R4, R0, #0xFF \n"
 633 "    AND     R0, R0, #0xFF00 \n"
 634 "    CMP     R0, #0x100 \n"
 635 "    BEQ     loc_FF865DD4 \n"
 636 "    CMP     R0, #0x200 \n"
 637 "    BEQ     loc_FF865E0C \n"
 638 "    CMP     R0, #0x300 \n"
 639 "    BEQ     loc_FF866004 \n"
 640 "    CMP     R0, #0x400 \n"
 641 "    BNE     loc_FF865D64 \n"
 642 "    CMP     R4, #0 \n"
 643 "    LDRNE   R1, =0x2ED \n"
 644 "    LDRNE   R0, =0xFF865FC4 /*'RotaryEncoder.c'*/ \n"
 645 "    BLNE    _DebugAssert \n"
 646 "    RSB     R0, R4, R4, LSL#3 \n"
 647 "    LDR     R0, [R6, R0, LSL#2] \n"
 648 
 649 "loc_FF865DCC:\n"
 650 "    BL      sub_FF866084 \n"
 651 "    B       loc_FF865D64 \n"
 652 
 653 "loc_FF865DD4:\n"
 654 //------------------  added code ---------------------
 655 "labelA:\n"
 656 "    LDR     R0, =jogdial_stopped\n"
 657 "    LDR     R0, [R0]\n"
 658 "    CMP     R0, #1\n"
 659 "    BNE     labelB\n"
 660 "    MOV     R0, #40\n"
 661 "    BL      _SleepTask\n"
 662 "    B       labelA\n"
 663 "labelB:\n"
 664 //------------------  original code ------------------
 665 "    LDR     R7, =0x2594 \n"
 666 "    LDR     R0, [R7, R4, LSL#2] \n"
 667 "    BL      sub_FF83B460 /*_CancelTimer*/ \n"
 668 "    LDR     R2, =0xFF865C54 \n"
 669 "    MOV     R1, R2 \n"
 670 "    ORR     R3, R4, #0x200 \n"
 671 "    MOV     R0, #0x28 \n"
 672 "    BL      sub_FF83B37C /*_SetTimerAfter*/ \n"
 673 "    TST     R0, #1 \n"
 674 "    CMPNE   R0, #0x15 \n"
 675 "    STR     R0, [R10, R4, LSL#2] \n"
 676 "    BEQ     loc_FF865D64 \n"
 677 "    MOV     R1, #0x274 \n"
 678 "    B       loc_FF865FB0 \n"
 679 
 680 "loc_FF865E0C:\n"
 681 "    RSB     R5, R4, R4, LSL#3 \n"
 682 "    LDR     R0, [R6, R5, LSL#2] \n"
 683 "    LDR     R1, =0xC0240104 \n"
 684 "    LDR     R0, [R1, R0, LSL#8] \n"
 685 "    MOV     R2, R0, ASR#16 \n"
 686 "    ADD     R0, SP, #0x14 \n"
 687 "    ADD     R0, R0, R4, LSL#1 \n"
 688 "    STR     R0, [SP, #0x18] \n"
 689 "    STRH    R2, [R0] \n"
 690 "    ADD     R0, SP, #0x10 \n"
 691 "    ADD     R11, R0, R4, LSL#1 \n"
 692 "    LDRSH   R3, [R11] \n"
 693 "    SUB     R0, R2, R3 \n"
 694 "    CMP     R0, #0 \n"
 695 "    BNE     loc_FF865E8C \n"
 696 "    LDR     R0, [R9, R4, LSL#2] \n"
 697 "    CMP     R0, #0 \n"
 698 "    BEQ     loc_FF865F6C \n"
 699 "    LDR     R7, =0x2594 \n"
 700 "    LDR     R0, [R7, R4, LSL#2] \n"
 701 "    BL      sub_FF83B460 /*_CancelTimer*/ \n"
 702 "    LDR     R2, =0xFF865C60 \n"
 703 "    MOV     R1, R2 \n"
 704 "    ORR     R3, R4, #0x300 \n"
 705 "    MOV     R0, #0x1F4 \n"
 706 "    BL      sub_FF83B37C /*_SetTimerAfter*/ \n"
 707 "    TST     R0, #1 \n"
 708 "    CMPNE   R0, #0x15 \n"
 709 "    STR     R0, [R7, R4, LSL#2] \n"
 710 "    BEQ     loc_FF865F6C \n"
 711 "    LDR     R1, =0x28D \n"
 712 "    B       loc_FF865F64 \n"
 713 
 714 "loc_FF865E8C:\n"
 715 "    MOV     R1, R0 \n"
 716 "    RSBLT   R0, R0, #0 \n"
 717 "    MOVLE   R7, #0 \n"
 718 "    MOVGT   R7, #1 \n"
 719 "    CMP     R0, #0xFF \n"
 720 "    BLS     loc_FF865ECC \n"
 721 "    CMP     R1, #0 \n"
 722 "    RSBLE   R0, R3, #0xFF \n"
 723 "    ADDLE   R0, R0, #0x7F00 \n"
 724 "    ADDLE   R0, R0, R2 \n"
 725 "    RSBGT   R0, R2, #0xFF \n"
 726 "    ADDGT   R0, R0, #0x7F00 \n"
 727 "    ADDGT   R0, R0, R3 \n"
 728 "    ADD     R0, R0, #0x8000 \n"
 729 "    ADD     R0, R0, #1 \n"
 730 "    EOR     R7, R7, #1 \n"
 731 
 732 "loc_FF865ECC:\n"
 733 "    STR     R0, [SP, #4] \n"
 734 "    LDR     R0, [R9, R4, LSL#2] \n"
 735 "    CMP     R0, #0 \n"
 736 "    ADDEQ   R0, R6, R5, LSL#2 \n"
 737 "    LDREQ   R0, [R0, #8] \n"
 738 "    BEQ     loc_FF865F04 \n"
 739 "    ADD     R8, R6, R5, LSL#2 \n"
 740 "    ADD     R1, R8, R7, LSL#2 \n"
 741 "    LDR     R1, [R1, #0x10] \n"
 742 "    CMP     R1, R0 \n"
 743 "    BEQ     loc_FF865F08 \n"
 744 "    LDR     R0, [R8, #0xC] \n"
 745 "    BL      sub_FF89FEC0 \n"
 746 "    LDR     R0, [R8, #8] \n"
 747 
 748 "loc_FF865F04:\n"
 749 "    BL      sub_FF89FEC0 \n"
 750 
 751 "loc_FF865F08:\n"
 752 "    ADD     R0, R6, R5, LSL#2 \n"
 753 "    ADD     R7, R0, R7, LSL#2 \n"
 754 "    LDR     R0, [R7, #0x10] \n"
 755 "    LDR     R1, [SP, #4] \n"
 756 "    BL      sub_FF89FDE8 \n"
 757 "    LDR     R0, [R7, #0x10] \n"
 758 "    LDR     R7, =0x2594 \n"
 759 "    STR     R0, [R9, R4, LSL#2] \n"
 760 "    LDR     R0, [SP, #0x18] \n"
 761 "    LDRH    R0, [R0] \n"
 762 "    STRH    R0, [R11] \n"
 763 "    LDR     R0, [R7, R4, LSL#2] \n"
 764 "    BL      sub_FF83B460 /*_CancelTimer*/ \n"
 765 "    LDR     R2, =0xFF865C60 \n"
 766 "    MOV     R1, R2 \n"
 767 "    ORR     R3, R4, #0x300 \n"
 768 "    MOV     R0, #0x1F4 \n"
 769 "    BL      sub_FF83B37C /*_SetTimerAfter*/ \n"
 770 "    TST     R0, #1 \n"
 771 "    CMPNE   R0, #0x15 \n"
 772 "    STR     R0, [R7, R4, LSL#2] \n"
 773 "    BEQ     loc_FF865F6C \n"
 774 "    LDR     R1, =0x2CF \n"
 775 
 776 "loc_FF865F64:\n"
 777 "    LDR     R0, =0xFF865FC4 /*'RotaryEncoder.c'*/ \n"
 778 "    BL      _DebugAssert \n"
 779 
 780 "loc_FF865F6C:\n"
 781 "    ADD     R0, R6, R5, LSL#2 \n"
 782 "    LDR     R0, [R0, #0x18] \n"
 783 "    CMP     R0, #1 \n"
 784 "    BNE     loc_FF865FFC \n"
 785 "    LDR     R0, =0x2588 \n"
 786 "    LDR     R0, [R0, #0x10] \n"
 787 "    CMP     R0, #0 \n"
 788 "    BEQ     loc_FF865FFC \n"
 789 "    LDR     R2, =0xFF865C54 \n"
 790 "    MOV     R1, R2 \n"
 791 "    ORR     R3, R4, #0x400 \n"
 792 "    BL      sub_FF83B37C /*_SetTimerAfter*/ \n"
 793 "    TST     R0, #1 \n"
 794 "    CMPNE   R0, #0x15 \n"
 795 "    STR     R0, [R10, R4, LSL#2] \n"
 796 "    BEQ     loc_FF865D64 \n"
 797 "    LDR     R1, =0x2D6 \n"
 798 
 799 "loc_FF865FB0:\n"
 800 "    LDR     R0, =0xFF865FC4 /*'RotaryEncoder.c'*/ \n"
 801 "    BL      _DebugAssert \n"
 802 "    B       loc_FF865D64 \n"
 803 
 804 "loc_FF865FFC:\n"
 805 "    LDR     R0, [R6, R5, LSL#2] \n"
 806 "    B       loc_FF865DCC \n"
 807 
 808 "loc_FF866004:\n"
 809 "    LDR     R0, [R9, R4, LSL#2] \n"
 810 "    CMP     R0, #0 \n"
 811 "    MOVEQ   R1, #0x2E0 \n"
 812 "    LDREQ   R0, =0xFF865FC4 /*'RotaryEncoder.c'*/ \n"
 813 "    BLEQ    _DebugAssert \n"
 814 "    RSB     R0, R4, R4, LSL#3 \n"
 815 "    ADD     R0, R6, R0, LSL#2 \n"
 816 "    LDR     R0, [R0, #0xC] \n"
 817 "    BL      sub_FF89FEC0 \n"
 818 "    MOV     R2, #0 \n"
 819 "    STR     R2, [R9, R4, LSL#2] \n"
 820 "    B       loc_FF865D64 \n"
 821 );
 822 }

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