root/platform/ixus1000_sd4500/sub/101a/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_FF8966E0_my
  12. sub_FF8753B8_my
  13. sub_FF874FE0_my
  14. sub_FF874D00_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, =0xFFC56D20 \n"
 134 "    LDR     R1, =0x1900 \n"
 135 "    LDR     R3, =0x10728 \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, =0x172BF8 \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;
 160 
 161     // replacement of sub_FF862AF4 for correct power-on.
 162     *(int*)(0x254C) = (*(int*)0xC022010C)&1 ? 0x400000 : 0x200000;
 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_FFB87588 \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, =0x172BF8 \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 = 0xFF81FBA8.
 272 );
 273 }
 274 
 275 /*************************************************************/
 276 //** taskcreate_Startup_my @ 0xFF81FBA8 - 0xFF81FC20, length=31
 277 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 278 asm volatile (
 279 "    STMFD   SP!, {R3-R5,LR} \n"
 280 //"  BL      _sub_FF862AEC \n"  // --> Nullsub call removed.
 281 "    BL      sub_FF83D1D4 \n"
 282 "    CMP     R0, #0 \n"
 283 "    BNE     loc_FF81FBFC \n"
 284 "    BL      sub_FF8370E8 /*_IsNormalCameraMode_FW*/ \n"
 285 "    CMP     R0, #0 \n"
 286 "    BEQ     loc_FF81FBFC \n"
 287 "    LDR     R4, =0xC0220000 \n"
 288 "    LDR     R0, [R4, #0x120] \n"
 289 "    TST     R0, #1 \n"
 290 "    MOVEQ   R0, #0x12C \n"
 291 "    BLEQ    _SleepTask \n"
 292 "    BL      sub_FF862AD0 \n"
 293 "    CMP     R0, #0 \n"
 294 "    BNE     loc_FF81FBFC \n"
 295 "    BL      sub_FF833F34 \n"
 296 "    MOV     R0, #0x44 \n"
 297 "    STR     R0, [R4, #0x1C] \n"
 298 "    BL      sub_FF834120 \n"
 299 
 300 "loc_FF81FBF8:\n"
 301 "    B       loc_FF81FBF8 \n"
 302 
 303 "loc_FF81FBFC:\n"
 304 //"  BL      _sub_FF862AF4 \n"  // See begin of sub_FF810354_my()
 305 //"  BL      _sub_FF862AF0 \n"  // --> Nullsub call removed.
 306 "    BL      sub_FF83B3EC \n"
 307 "    LDR     R1, =0x3CE000 \n"
 308 "    MOV     R0, #0 \n"
 309 "    BL      sub_FF83B834 \n"
 310 "    BL      sub_FF83B5E0 \n"
 311 "    MOV     R3, #0 \n"
 312 "    STR     R3, [SP] \n"
 313 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF81FAF0.
 314 "    LDR     PC, =0xFF81FC24 \n"  // Continue in firmware
 315 );
 316 }
 317 
 318 /*************************************************************/
 319 //** task_Startup_my @ 0xFF81FAF0 - 0xFF81FB74, length=34
 320 void __attribute__((naked,noinline)) task_Startup_my() {
 321 asm volatile (
 322 "    STMFD   SP!, {R4,LR} \n"
 323 "    BL      sub_FF816594 \n"
 324 "    BL      sub_FF835A30 \n"
 325 "    BL      sub_FF833B3C \n"
 326 //"  BL      _sub_FF863528 \n"  // --> Nullsub call removed.
 327 "    BL      sub_FF83D404 \n"
 328 //"  BL      _sub_FF83D2AC \n"  // start diskboot.bin
 329 "    BL      sub_FF89C91C \n"
 330 "    BL      sub_FF81648C \n"
 331 "    BL      sub_FF836754 \n"
 332 "    LDR     R1, =0x7C007C00 \n"
 333 "    LDR     R0, =0xC0F1800C \n"
 334 "    BL      sub_FF835A3C /*_EngDrvOut*/ \n"
 335 "    LDR     R0, =0xC0F18010 \n"
 336 "    MOV     R1, #0 \n"
 337 "    BL      sub_FF835A3C /*_EngDrvOut*/ \n"
 338 "    LDR     R0, =0xC0F18018 \n"
 339 "    MOV     R1, #0 \n"
 340 "    BL      sub_FF835A3C /*_EngDrvOut*/ \n"
 341 "    LDR     R0, =0xC0F1801C \n"
 342 "    MOV     R1, #0x1000 \n"
 343 "    BL      sub_FF835A3C /*_EngDrvOut*/ \n"
 344 "    LDR     R0, =0xC0F18020 \n"
 345 "    MOV     R1, #8 \n"
 346 "    BL      sub_FF835A3C /*_EngDrvOut*/ \n"
 347 "    LDR     R0, =0xC022D06C \n"
 348 "    MOV     R1, #0xE000000 \n"
 349 "    BL      sub_FF835A3C /*_EngDrvOut*/ \n"
 350 "    BL      sub_FF8164CC \n"
 351 "    BL      sub_FF8324F4 \n"
 352 "    BL      sub_FF83D434 \n"
 353 "    BL      sub_FF83AB90 \n"
 354 "    BL      sub_FF83D5B0 \n"
 355 
 356 "    BL      CreateTask_spytask\n"  // added
 357 
 358 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFF834788.
 359 "    LDR     PC, =0xFF81FB78 \n"  // Continue in firmware
 360 );
 361 }
 362 
 363 /*************************************************************/
 364 //** taskcreatePhySw_my @ 0xFF834788 - 0xFF8347A8, length=9
 365 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 366 asm volatile (
 367 "    STMFD   SP!, {R3-R5,LR} \n"
 368 "    LDR     R4, =0x1C34 \n"
 369 "    LDR     R0, [R4, #0x10] \n"
 370 "    CMP     R0, #0 \n"
 371 "    BNE     sub_FF8347BC \n"
 372 "    MOV     R3, #0 \n"
 373 "    STR     R3, [SP] \n"
 374 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF834754.
 375 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw
 376 "    LDR     PC, =0xFF8347AC \n"  // Continue in firmware
 377 );
 378 }
 379 
 380 /*************************************************************/
 381 //** init_file_modules_task @ 0xFF8A01E0 - 0xFF8A01FC, length=8
 382 void __attribute__((naked,noinline)) init_file_modules_task() {
 383 asm volatile (
 384 "    STMFD   SP!, {R4-R6,LR} \n"
 385 "    BL      sub_FF8966B4 \n"
 386 "    LDR     R5, =0x5006 \n"
 387 "    MOVS    R4, R0 \n"
 388 "    MOVNE   R1, #0 \n"
 389 "    MOVNE   R0, R5 \n"
 390 "    BLNE    _PostLogicalEventToUI \n"
 391 "    BL      sub_FF8966E0_my \n"  // --> Patched. Old value = 0xFF8966E0.
 392 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 393 "    LDR     PC, =0xFF8A0200 \n"  // Continue in firmware
 394 );
 395 }
 396 
 397 /*************************************************************/
 398 //** sub_FF8966E0_my @ 0xFF8966E0 - 0xFF8966E8, length=3
 399 void __attribute__((naked,noinline)) sub_FF8966E0_my() {
 400 asm volatile (
 401 "    STMFD   SP!, {R4,LR} \n"
 402 "    MOV     R0, #3 \n"
 403 "    BL      sub_FF8753B8_my \n"  // --> Patched. Old value = 0xFF8753B8.
 404 "    LDR     PC, =0xFF8966EC \n"  // Continue in firmware
 405 );
 406 }
 407 
 408 /*************************************************************/
 409 //** sub_FF8753B8_my @ 0xFF8753B8 - 0xFF87540C, length=22
 410 void __attribute__((naked,noinline)) sub_FF8753B8_my() {
 411 asm volatile (
 412 "    STMFD   SP!, {R4-R8,LR} \n"
 413 "    MOV     R8, R0 \n"
 414 "    BL      sub_FF875338 \n"
 415 "    LDR     R1, =0x3A068 \n"
 416 "    MOV     R6, R0 \n"
 417 "    ADD     R4, R1, R0, LSL#7 \n"
 418 "    LDR     R0, [R4, #0x6C] \n"
 419 "    CMP     R0, #4 \n"
 420 "    LDREQ   R1, =0x83F \n"
 421 "    LDREQ   R0, =0xFF874E78 /*'Mounter.c'*/ \n"
 422 "    BLEQ    _DebugAssert \n"
 423 "    MOV     R1, R8 \n"
 424 "    MOV     R0, R6 \n"
 425 "    BL      sub_FF874BEC \n"
 426 "    LDR     R0, [R4, #0x38] \n"
 427 "    BL      sub_FF875A5C \n"
 428 "    CMP     R0, #0 \n"
 429 "    STREQ   R0, [R4, #0x6C] \n"
 430 "    MOV     R0, R6 \n"
 431 "    BL      sub_FF874C7C \n"
 432 "    MOV     R0, R6 \n"
 433 "    BL      sub_FF874FE0_my \n"  // --> Patched. Old value = 0xFF874FE0.
 434 "    LDR     PC, =0xFF875410 \n"  // Continue in firmware
 435 );
 436 }
 437 
 438 /*************************************************************/
 439 //** sub_FF874FE0_my @ 0xFF874FE0 - 0xFF875008, length=11
 440 void __attribute__((naked,noinline)) sub_FF874FE0_my() {
 441 asm volatile (
 442 "    STMFD   SP!, {R4-R6,LR} \n"
 443 "    MOV     R5, R0 \n"
 444 "    LDR     R0, =0x3A068 \n"
 445 "    ADD     R4, R0, R5, LSL#7 \n"
 446 "    LDR     R0, [R4, #0x6C] \n"
 447 "    TST     R0, #2 \n"
 448 "    MOVNE   R0, #1 \n"
 449 "    LDMNEFD SP!, {R4-R6,PC} \n"
 450 "    LDR     R0, [R4, #0x38] \n"
 451 "    MOV     R1, R5 \n"
 452 "    BL      sub_FF874D00_my \n"  // --> Patched. Old value = 0xFF874D00.
 453 "    LDR     PC, =0xFF87500C \n"  // Continue in firmware
 454 );
 455 }
 456 
 457 /*************************************************************/
 458 //** sub_FF874D00_my @ 0xFF874D00 - 0xFF874E70, length=93
 459 void __attribute__((naked,noinline)) sub_FF874D00_my() {
 460 asm volatile (
 461 "    STMFD   SP!, {R4-R10,LR} \n"
 462 "    MOV     R9, R0 \n"
 463 "    LDR     R0, =0x3A068 \n"
 464 "    MOV     R8, #0 \n"
 465 "    ADD     R5, R0, R1, LSL#7 \n"
 466 "    LDR     R0, [R5, #0x3C] \n"
 467 "    MOV     R7, #0 \n"
 468 "    CMP     R0, #7 \n"
 469 "    MOV     R6, #0 \n"
 470 "    ADDLS   PC, PC, R0, LSL#2 \n"
 471 "    B       loc_FF874E58 \n"
 472 "    B       loc_FF874D64 \n"
 473 "    B       loc_FF874D4C \n"
 474 "    B       loc_FF874D4C \n"
 475 "    B       loc_FF874D4C \n"
 476 "    B       loc_FF874D4C \n"
 477 "    B       loc_FF874E50 \n"
 478 "    B       loc_FF874D4C \n"
 479 "    B       loc_FF874D4C \n"
 480 
 481 "loc_FF874D4C:\n"
 482 "    MOV     R2, #0 \n"
 483 "    MOV     R1, #0x200 \n"
 484 "    MOV     R0, #2 \n"
 485 "    BL      sub_FF890764 \n"
 486 "    MOVS    R4, R0 \n"
 487 "    BNE     loc_FF874D6C \n"
 488 
 489 "loc_FF874D64:\n"
 490 "    MOV     R0, #0 \n"
 491 "    LDMFD   SP!, {R4-R10,PC} \n"
 492 
 493 "loc_FF874D6C:\n"
 494 "    LDR     R12, [R5, #0x50] \n"
 495 "    MOV     R3, R4 \n"
 496 "    MOV     R2, #1 \n"
 497 "    MOV     R1, #0 \n"
 498 "    MOV     R0, R9 \n"
 499 "    BLX     R12 \n"
 500 "    CMP     R0, #1 \n"
 501 "    BNE     loc_FF874D98 \n"
 502 "    MOV     R0, #2 \n"
 503 "    BL      sub_FF8908B4 \n"
 504 "    B       loc_FF874D64 \n"
 505 
 506 "loc_FF874D98:\n"
 507 "    LDR     R1, [R5, #0x64] \n"
 508 "    MOV     R0, R9 \n"
 509 "    BLX     R1 \n"
 510 
 511 "    MOV     R1, R4\n"              //  pointer to MBR in R1
 512 "    BL      mbr_read_dryos\n"      //  total sectors count in R0 before and after call
 513 
 514 // Start of DataGhost's FAT32 autodetection code
 515 // Policy: If there is a partition which has type W95 FAT32, use the first one of those for image storage
 516 // According to the code below, we can use R1, R2, R3 and R12.
 517 // LR wasn't really used anywhere but for storing a part of the partition signature. This is the only thing
 518 // that won't work with an offset, but since we can load from LR+offset into LR, we can use this to do that :)
 519 "    MOV     R12, R4\n"             // Copy the MBR start address so we have something to work with
 520 "    MOV     LR, R4\n"              // Save old offset for MBR signature
 521 "    MOV     R1, #1\n"              // Note the current partition number
 522 "    B       dg_sd_fat32_enter\n"   // We actually need to check the first partition as well, no increments yet!
 523 "dg_sd_fat32:\n"
 524 "    CMP     R1, #4\n"              // Did we already see the 4th partition?
 525 "    BEQ     dg_sd_fat32_end\n"     // Yes, break. We didn't find anything, so don't change anything.
 526 "    ADD     R12, R12, #0x10\n"     // Second partition
 527 "    ADD     R1, R1, #1\n"          // Second partition for the loop
 528 "dg_sd_fat32_enter:\n"
 529 "    LDRB    R2, [R12, #0x1BE]\n"   // Partition status
 530 "    LDRB    R3, [R12, #0x1C2]\n"   // Partition type (FAT32 = 0xB)
 531 "    CMP     R3, #0xB\n"            // Is this a FAT32 partition?
 532 "    CMPNE   R3, #0xC\n"            // Not 0xB, is it 0xC (FAT32 LBA) then?
 533 "    CMPNE   R3, #0x7\n"            // exFat?
 534 "    BNE     dg_sd_fat32\n"         // No, it isn't. Loop again.
 535 "    CMP     R2, #0x00\n"           // It is, check the validity of the partition type
 536 "    CMPNE   R2, #0x80\n"
 537 "    BNE     dg_sd_fat32\n"         // Invalid, go to next partition
 538                                     // This partition is valid, it's the first one, bingo!
 539 "    MOV     R4, R12\n"             // Move the new MBR offset for the partition detection.
 540 
 541 "dg_sd_fat32_end:\n"
 542 // End of DataGhost's FAT32 autodetection code
 543 
 544 "    LDRB    R1, [R4, #0x1C9] \n"
 545 "    LDRB    R3, [R4, #0x1C8] \n"
 546 "    LDRB    R12, [R4, #0x1CC] \n"
 547 "    MOV     R1, R1, LSL#24 \n"
 548 "    ORR     R1, R1, R3, LSL#16 \n"
 549 "    LDRB    R3, [R4, #0x1C7] \n"
 550 "    LDRB    R2, [R4, #0x1BE] \n"
 551 //"  LDRB    LR, [R4, #0x1FF] \n"  // replaced below
 552 "    ORR     R1, R1, R3, LSL#8 \n"
 553 "    LDRB    R3, [R4, #0x1C6] \n"
 554 "    CMP     R2, #0 \n"
 555 "    CMPNE   R2, #0x80 \n"
 556 "    ORR     R1, R1, R3 \n"
 557 "    LDRB    R3, [R4, #0x1CD] \n"
 558 "    MOV     R3, R3, LSL#24 \n"
 559 "    ORR     R3, R3, R12, LSL#16 \n"
 560 "    LDRB    R12, [R4, #0x1CB] \n"
 561 "    ORR     R3, R3, R12, LSL#8 \n"
 562 "    LDRB    R12, [R4, #0x1CA] \n"
 563 "    ORR     R3, R3, R12 \n"
 564 //"  LDRB    R12, [R4, #0x1FE] \n"  // replaced below
 565 "    LDRB    R12, [LR,#0x1FE]\n"    // replace instructions above
 566 "    LDRB    LR, [LR,#0x1FF]\n"     // replace instructions above
 567 "    BNE     loc_FF874E24 \n"
 568 "    CMP     R0, R1 \n"
 569 "    BCC     loc_FF874E24 \n"
 570 "    ADD     R2, R1, R3 \n"
 571 "    CMP     R2, R0 \n"
 572 "    CMPLS   R12, #0x55 \n"
 573 "    CMPEQ   LR, #0xAA \n"
 574 "    MOVEQ   R7, R1 \n"
 575 "    MOVEQ   R6, R3 \n"
 576 "    MOVEQ   R4, #1 \n"
 577 "    BEQ     loc_FF874E28 \n"
 578 
 579 "loc_FF874E24:\n"
 580 "    MOV     R4, R8 \n"
 581 
 582 "loc_FF874E28:\n"
 583 "    MOV     R0, #2 \n"
 584 "    BL      sub_FF8908B4 \n"
 585 "    CMP     R4, #0 \n"
 586 "    BNE     loc_FF874E64 \n"
 587 "    LDR     R1, [R5, #0x64] \n"
 588 "    MOV     R7, #0 \n"
 589 "    MOV     R0, R9 \n"
 590 "    BLX     R1 \n"
 591 "    MOV     R6, R0 \n"
 592 "    B       loc_FF874E64 \n"
 593 
 594 "loc_FF874E50:\n"
 595 "    MOV     R6, #0x40 \n"
 596 "    B       loc_FF874E64 \n"
 597 
 598 "loc_FF874E58:\n"
 599 "    LDR     R1, =0x597 \n"
 600 "    LDR     R0, =0xFF874E78 /*'Mounter.c'*/ \n"
 601 "    BL      _DebugAssert \n"
 602 
 603 "loc_FF874E64:\n"
 604 "    STR     R7, [R5, #0x44]! \n"
 605 "    STMIB   R5, {R6,R8} \n"
 606 "    MOV     R0, #1 \n"
 607 "    LDMFD   SP!, {R4-R10,PC} \n"
 608 );
 609 }
 610 
 611 /*************************************************************/
 612 //** JogDial_task_my @ 0xFF863668 - 0xFF863990, length=203
 613 void __attribute__((naked,noinline)) JogDial_task_my() {
 614 asm volatile (
 615 "    STMFD   SP!, {R4-R11,LR} \n"
 616 "    SUB     SP, SP, #0x1C \n"
 617 "    BL      sub_FF863A94 \n"
 618 "    LDR     R1, =0x2560 \n"
 619 "    LDR     R6, =0xFFB8D62C \n"
 620 "    MOV     R0, #0 \n"
 621 "    ADD     R3, SP, #0x10 \n"
 622 
 623 // Save pointer for kbd.c routine
 624 "    LDR     R12, =jog_position \n"
 625 "    STR     R3, [R12] \n"
 626 
 627 "    ADD     R12, SP, #0x14 \n"
 628 "    ADD     R10, SP, #8 \n"
 629 "    MOV     R2, #0 \n"
 630 "    ADD     R9, SP, #0xC \n"
 631 
 632 "loc_FF863694:\n"
 633 "    ADD     R12, SP, #0x14 \n"
 634 "    ADD     LR, R12, R0, LSL#1 \n"
 635 "    MOV     R2, #0 \n"
 636 "    ADD     R3, SP, #0x10 \n"
 637 "    STRH    R2, [LR] \n"
 638 "    ADD     LR, R3, R0, LSL#1 \n"
 639 "    STRH    R2, [LR] \n"
 640 "    STR     R2, [R9, R0, LSL#2] \n"
 641 "    STR     R2, [R10, R0, LSL#2] \n"
 642 "    ADD     R0, R0, #1 \n"
 643 "    CMP     R0, #1 \n"
 644 "    BLT     loc_FF863694 \n"
 645 
 646 "loc_FF8636C4:\n"
 647 "    LDR     R0, =0x2560 \n"
 648 "    MOV     R2, #0 \n"
 649 "    LDR     R0, [R0, #0xC] \n"
 650 "    MOV     R1, SP \n"
 651 "    BL      sub_FF83AE20 /*_ReceiveMessageQueue*/ \n"
 652 "    CMP     R0, #0 \n"
 653 "    LDRNE   R1, =0x262 \n"
 654 "    LDRNE   R0, =0xFF863924 /*'RotaryEncoder.c'*/ \n"
 655 "    BLNE    _DebugAssert \n"
 656 "    LDR     R0, [SP] \n"
 657 "    AND     R4, R0, #0xFF \n"
 658 "    AND     R0, R0, #0xFF00 \n"
 659 "    CMP     R0, #0x100 \n"
 660 "    BEQ     loc_FF863734 \n"
 661 "    CMP     R0, #0x200 \n"
 662 "    BEQ     loc_FF86376C \n"
 663 "    CMP     R0, #0x300 \n"
 664 "    BEQ     loc_FF863964 \n"
 665 "    CMP     R0, #0x400 \n"
 666 "    BNE     loc_FF8636C4 \n"
 667 "    CMP     R4, #0 \n"
 668 "    LDRNE   R1, =0x2ED \n"
 669 "    LDRNE   R0, =0xFF863924 /*'RotaryEncoder.c'*/ \n"
 670 "    BLNE    _DebugAssert \n"
 671 "    RSB     R0, R4, R4, LSL#3 \n"
 672 "    LDR     R0, [R6, R0, LSL#2] \n"
 673 
 674 "loc_FF86372C:\n"
 675 "    BL      sub_FF863A6C \n"
 676 "    B       loc_FF8636C4 \n"
 677 
 678 "loc_FF863734:\n"
 679 //------------------  added code ---------------------
 680 "labelA:\n"
 681 "    LDR     R0, =jogdial_stopped\n"
 682 "    LDR     R0, [R0]\n"
 683 "    CMP     R0, #1\n"
 684 "    BNE     labelB\n"
 685 "    MOV     R0, #40\n"
 686 "    BL      _SleepTask\n"
 687 "    B       labelA\n"
 688 "labelB:\n"
 689 //------------------  original code ------------------
 690 "    LDR     R7, =0x2570 \n"
 691 "    LDR     R0, [R7, R4, LSL#2] \n"
 692 "    BL      sub_FF83BDB8 /*_CancelTimer*/ \n"
 693 "    LDR     R2, =0xFF8635B4 \n"
 694 "    MOV     R1, R2 \n"
 695 "    ORR     R3, R4, #0x200 \n"
 696 "    MOV     R0, #0x28 \n"
 697 "    BL      sub_FF83BCD4 /*_SetTimerAfter*/ \n"
 698 "    TST     R0, #1 \n"
 699 "    CMPNE   R0, #0x15 \n"
 700 "    STR     R0, [R10, R4, LSL#2] \n"
 701 "    BEQ     loc_FF8636C4 \n"
 702 "    MOV     R1, #0x274 \n"
 703 "    B       loc_FF863910 \n"
 704 
 705 "loc_FF86376C:\n"
 706 "    RSB     R5, R4, R4, LSL#3 \n"
 707 "    LDR     R0, [R6, R5, LSL#2] \n"
 708 "    LDR     R1, =0xC0240104 \n"
 709 "    LDR     R0, [R1, R0, LSL#8] \n"
 710 "    MOV     R2, R0, ASR#16 \n"
 711 "    ADD     R0, SP, #0x14 \n"
 712 "    ADD     R0, R0, R4, LSL#1 \n"
 713 "    STR     R0, [SP, #0x18] \n"
 714 "    STRH    R2, [R0] \n"
 715 "    ADD     R0, SP, #0x10 \n"
 716 "    ADD     R11, R0, R4, LSL#1 \n"
 717 "    LDRSH   R3, [R11] \n"
 718 "    SUB     R0, R2, R3 \n"
 719 "    CMP     R0, #0 \n"
 720 "    BNE     loc_FF8637EC \n"
 721 "    LDR     R0, [R9, R4, LSL#2] \n"
 722 "    CMP     R0, #0 \n"
 723 "    BEQ     loc_FF8638CC \n"
 724 "    LDR     R7, =0x2570 \n"
 725 "    LDR     R0, [R7, R4, LSL#2] \n"
 726 "    BL      sub_FF83BDB8 /*_CancelTimer*/ \n"
 727 "    LDR     R2, =0xFF8635C0 \n"
 728 "    MOV     R1, R2 \n"
 729 "    ORR     R3, R4, #0x300 \n"
 730 "    MOV     R0, #0x1F4 \n"
 731 "    BL      sub_FF83BCD4 /*_SetTimerAfter*/ \n"
 732 "    TST     R0, #1 \n"
 733 "    CMPNE   R0, #0x15 \n"
 734 "    STR     R0, [R7, R4, LSL#2] \n"
 735 "    BEQ     loc_FF8638CC \n"
 736 "    LDR     R1, =0x28D \n"
 737 "    B       loc_FF8638C4 \n"
 738 
 739 "loc_FF8637EC:\n"
 740 "    MOV     R1, R0 \n"
 741 "    RSBLT   R0, R0, #0 \n"
 742 "    MOVLE   R7, #0 \n"
 743 "    MOVGT   R7, #1 \n"
 744 "    CMP     R0, #0xFF \n"
 745 "    BLS     loc_FF86382C \n"
 746 "    CMP     R1, #0 \n"
 747 "    RSBLE   R0, R3, #0xFF \n"
 748 "    ADDLE   R0, R0, #0x7F00 \n"
 749 "    ADDLE   R0, R0, R2 \n"
 750 "    RSBGT   R0, R2, #0xFF \n"
 751 "    ADDGT   R0, R0, #0x7F00 \n"
 752 "    ADDGT   R0, R0, R3 \n"
 753 "    ADD     R0, R0, #0x8000 \n"
 754 "    ADD     R0, R0, #1 \n"
 755 "    EOR     R7, R7, #1 \n"
 756 
 757 "loc_FF86382C:\n"
 758 "    STR     R0, [SP, #4] \n"
 759 "    LDR     R0, [R9, R4, LSL#2] \n"
 760 "    CMP     R0, #0 \n"
 761 "    ADDEQ   R0, R6, R5, LSL#2 \n"
 762 "    LDREQ   R0, [R0, #8] \n"
 763 "    BEQ     loc_FF863864 \n"
 764 "    ADD     R8, R6, R5, LSL#2 \n"
 765 "    ADD     R1, R8, R7, LSL#2 \n"
 766 "    LDR     R1, [R1, #0x10] \n"
 767 "    CMP     R1, R0 \n"
 768 "    BEQ     loc_FF863868 \n"
 769 "    LDR     R0, [R8, #0xC] \n"
 770 "    BL      sub_FF89C310 \n"
 771 "    LDR     R0, [R8, #8] \n"
 772 
 773 "loc_FF863864:\n"
 774 "    BL      sub_FF89C310 \n"
 775 
 776 "loc_FF863868:\n"
 777 "    ADD     R0, R6, R5, LSL#2 \n"
 778 "    ADD     R7, R0, R7, LSL#2 \n"
 779 "    LDR     R0, [R7, #0x10] \n"
 780 "    LDR     R1, [SP, #4] \n"
 781 "    BL      sub_FF89C238 \n"
 782 "    LDR     R0, [R7, #0x10] \n"
 783 "    LDR     R7, =0x2570 \n"
 784 "    STR     R0, [R9, R4, LSL#2] \n"
 785 "    LDR     R0, [SP, #0x18] \n"
 786 "    LDRH    R0, [R0] \n"
 787 "    STRH    R0, [R11] \n"
 788 "    LDR     R0, [R7, R4, LSL#2] \n"
 789 "    BL      sub_FF83BDB8 /*_CancelTimer*/ \n"
 790 "    LDR     R2, =0xFF8635C0 \n"
 791 "    MOV     R1, R2 \n"
 792 "    ORR     R3, R4, #0x300 \n"
 793 "    MOV     R0, #0x1F4 \n"
 794 "    BL      sub_FF83BCD4 /*_SetTimerAfter*/ \n"
 795 "    TST     R0, #1 \n"
 796 "    CMPNE   R0, #0x15 \n"
 797 "    STR     R0, [R7, R4, LSL#2] \n"
 798 "    BEQ     loc_FF8638CC \n"
 799 "    LDR     R1, =0x2CF \n"
 800 
 801 "loc_FF8638C4:\n"
 802 "    LDR     R0, =0xFF863924 /*'RotaryEncoder.c'*/ \n"
 803 "    BL      _DebugAssert \n"
 804 
 805 "loc_FF8638CC:\n"
 806 "    ADD     R0, R6, R5, LSL#2 \n"
 807 "    LDR     R0, [R0, #0x18] \n"
 808 "    CMP     R0, #1 \n"
 809 "    BNE     loc_FF86395C \n"
 810 "    LDR     R0, =0x2560 \n"
 811 "    LDR     R0, [R0, #0x14] \n"
 812 "    CMP     R0, #0 \n"
 813 "    BEQ     loc_FF86395C \n"
 814 "    LDR     R2, =0xFF8635B4 \n"
 815 "    MOV     R1, R2 \n"
 816 "    ORR     R3, R4, #0x400 \n"
 817 "    BL      sub_FF83BCD4 /*_SetTimerAfter*/ \n"
 818 "    TST     R0, #1 \n"
 819 "    CMPNE   R0, #0x15 \n"
 820 "    STR     R0, [R10, R4, LSL#2] \n"
 821 "    BEQ     loc_FF8636C4 \n"
 822 "    LDR     R1, =0x2D6 \n"
 823 
 824 "loc_FF863910:\n"
 825 "    LDR     R0, =0xFF863924 /*'RotaryEncoder.c'*/ \n"
 826 "    BL      _DebugAssert \n"
 827 "    B       loc_FF8636C4 \n"
 828 
 829 "loc_FF86395C:\n"
 830 "    LDR     R0, [R6, R5, LSL#2] \n"
 831 "    B       loc_FF86372C \n"
 832 
 833 "loc_FF863964:\n"
 834 "    LDR     R0, [R9, R4, LSL#2] \n"
 835 "    CMP     R0, #0 \n"
 836 "    MOVEQ   R1, #0x2E0 \n"
 837 "    LDREQ   R0, =0xFF863924 /*'RotaryEncoder.c'*/ \n"
 838 "    BLEQ    _DebugAssert \n"
 839 "    RSB     R0, R4, R4, LSL#3 \n"
 840 "    ADD     R0, R6, R0, LSL#2 \n"
 841 "    LDR     R0, [R0, #0xC] \n"
 842 "    BL      sub_FF89C310 \n"
 843 "    MOV     R2, #0 \n"
 844 "    STR     R2, [R9, R4, LSL#2] \n"
 845 "    B       loc_FF8636C4 \n"
 846 );
 847 }

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