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

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