root/platform/m3/sub/101a/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. save_romlog2
  2. spytask_my
  3. spytask
  4. CreateTask_spytask
  5. boot
  6. CreateTask_my
  7. sub_fc062f48_my
  8. sub_fc0630d9_my
  9. sub_fc0634e2_my
  10. sub_fc06347d_my
  11. sub_fc083bea_my
  12. init_file_modules_task
  13. kbd_p2_f_my
  14. sub_fc074e8a_my
  15. wrap_kbd_p1_f
  16. sub_fc0839d8_my
  17. sub_fc07507e_my

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "dryos31.h"
   5 #include "core.h"
   6 #include "callfunc.h"
   7 
   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 
  23 extern unsigned _ExecuteEventProcedure(const char *name,...);
  24 //extern unsigned _sprintf(char *stream, const char *format,...);
  25 
  26 extern unsigned _LCDMsg_Create (unsigned, unsigned, unsigned);
  27 extern void _LCDMsg_SetStr (unsigned, char * );
  28 //extern long _VbattGet();
  29 
  30 
  31 // code to support saving a romlog if started with some key combo
  32 #ifdef BOOT_ROMLOG_SHORTCUT
  33 void save_romlog2(void)
  34 {
  35         unsigned args[4];
  36     args[0] = (unsigned)"SystemEventInit";
  37         call_func_ptr(_ExecuteEventProcedure,args,1);
  38                 args[0] = (unsigned)"UI.CreatePublic";
  39                 call_func_ptr(_ExecuteEventProcedure,args,1);
  40         args[0] = (unsigned)"System.Create";
  41         call_func_ptr(_ExecuteEventProcedure,args,1);
  42                 args[0] = (unsigned)"Driver.Create";
  43                 call_func_ptr(_ExecuteEventProcedure,args,1);
  44 
  45                 args[0] = (unsigned)"GetLogToFile";
  46                 args[1] = (unsigned)"A/ROMLOG.LOG";
  47                 args[2] = 1;
  48                 call_func_ptr(_ExecuteEventProcedure,args,3);
  49 
  50                 args[0] = (unsigned)"BeepDrive";
  51                 args[1] = (unsigned) 0x02;
  52                 call_func_ptr(_ExecuteEventProcedure,args,2);
  53 
  54                  // *(int*)0xd20b0810  = 0x4d0002;       // Orange Led = on
  55 
  56 }
  57 
  58 
  59 /*----------------------------------------------------------------------
  60     spytask  MY
  61 -----------------------------------------------------------------------*/
  62 void spytask_my(long ua, long ub, long uc, long ud, long ue, long uf)
  63 {
  64     (void)ua; (void)ub; (void)uc; (void)ud; (void)ue; (void)uf;
  65 
  66         _SleepTask(2800);
  67         save_romlog2();
  68 
  69         while (1){
  70         _SleepTask(300);
  71         }
  72 }
  73 #endif // BOOT_ROMLOG_SHORTCUT
  74 
  75 /*----------------------------------------------------------------------
  76     spytask
  77 -----------------------------------------------------------------------*/
  78 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  79 {
  80     (void)ua; (void)ub; (void)uc; (void)ud; (void)ue; (void)uf;
  81     core_spytask();
  82 }
  83 
  84 
  85 /*----------------------------------------------------------------------
  86     CreateTask_spytask
  87 -----------------------------------------------------------------------*/
  88 void CreateTask_spytask()
  89 {
  90     // workaround to avoid crashes on startup triggered by closing the battery cover or after attaching / removing the lens
  91     // see https://chdk.setepontos.com/index.php?topic=12542.msg145817#msg145817
  92         if ( *(int*)(0x9e5c) & 0x00600000 )
  93     {
  94 #ifdef BOOT_ROMLOG_SHORTCUT
  95                 if (( *(int*)(0xD20BF4A0) & 0x00002000) == 0) _CreateTask("SpyTaskMY", 0x19, 0x2000, spytask_my, 0);
  96 #endif
  97                 _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
  98     }
  99 }
 100 
 101 ///*----------------------------------------------------------------------
 102 // Pointer to stack location where jogdial task records previous and current
 103 // jogdial positions
 104 // short *jog_position;
 105 
 106 /*----------------------------------------------------------------------
 107     boot()
 108 
 109     Main entry point for the CHDK code
 110 -----------------------------------------------------------------------*/
 111 
 112 /*************************************************************/
 113 void __attribute__((naked,noinline)) boot() {
 114     asm volatile ( // 0xfc02000c
 115                 "mov     r0, #0x4000\n"
 116                 "mov     sp, r0\n"
 117                 "bl      sub_fc02007e\n"
 118                 "ldr     r2, =0xc0242010\n"
 119                 "ldr     r1, [r2]\n"
 120                 "orr.w   r1, r1, #1\n"
 121                 "str     r1, [r2]\n"
 122                 "ldr     r0, =0xfccabee8\n"
 123                 "ldr     r1, =0x10e1000\n"
 124                 "ldr     r3, =0x11074ac\n"
 125                 "loc_fc02002a: \n"
 126                 "cmp     r1, r3\n"
 127                 "itt cc\n"
 128                 "ldrcc.w r2, [r0],#4\n"
 129                 "strcc.w r2, [r1],#4\n"
 130                 "bcc     loc_fc02002a\n"
 131                 "ldr     r0, =0x010e1000\n"
 132                 "ldr     r1, =0x000264ac\n"
 133                 "bl      sub_fc1300b2\n"
 134                 "ldr     r0, =0xfccd2394\n"
 135                 "ldr     r1, =0xbfe10800\n"
 136                 "ldr     r3, =0xbfe17391\n"
 137                 "loc_fc020046:\n"
 138                 "cmp     r1, r3\n"
 139                 "itt cc\n"
 140                 "ldrcc.w r2, [r0],#4\n"
 141                 "strcc.w r2, [r1],#4\n"
 142                 "bcc     loc_fc020046\n"
 143                 "ldr     r0, =0xfcc637a8\n"
 144                 "ldr     r1, =0x00008000\n"
 145                 "ldr     r3, =0x00050740\n"
 146                 "loc_fc02005a:\n"
 147                 "cmp     r1, r3\n"
 148                 "itt cc\n"
 149                 "ldrcc.w r2, [r0],#4\n"
 150                 "strcc.w r2, [r1],#4\n"
 151                 "bcc     loc_fc02005a\n"
 152 
 153                 "mov.w     r3, #0x01\n"                         // Enable TIO
 154                 "ldr     r1, =0x00008000\n"             // Enable TIO
 155                 "str.w     r3, [r1]\n"                          // Enable TIO
 156 
 157                 "ldr     r3, =0x00050740\n"
 158                 "ldr     r1, =0x003a7c80\n"
 159                 "mov.w   r2, #0\n"
 160                 "loc_fc020070:\n"
 161                 "cmp     r3, r1\n"
 162                 "it cc\n"
 163                 "strcc.w r2, [r3],#4\n"
 164                 "bcc     loc_fc020070\n"
 165 
 166         // Install CreateTask patch
 167         "adr     r0, patch_CreateTask\n"    // Patch data
 168         "ldm     r0, {r1,r2}\n"             // Get two patch instructions
 169         "ldr     r0, =orig_CreateTask\n"    // Address to patch
 170         "bic     r0, #1\n"                  // clear thumb bit
 171         "stm     r0, {r1,r2}\n"             // Store patch instructions
 172 
 173                 "b.w     sub_fc062f48_my\n" // continue
 174 
 175         "patch_CreateTask:\n"
 176         "ldr.w   pc, [pc,#0]\n"             // Do jump to absolute address CreateTask_my
 177         ".long   CreateTask_my + 1\n"           // has to be a thumb address
 178 );
 179 }
 180 
 181 /*************************************************************/
 182 void __attribute__((naked,noinline)) CreateTask_my() {
 183 
 184 //   *(int*)0xd20b0810  = 0x4d0002;
 185 asm volatile (
 186 "    push   {r0}\n"
 187 
 188 /* "    push   {r1}\n"
 189 "       ldr r0, =#0x4d0002\n"
 190 "       ldr r1, =#0xd20b0810\n"    // beam address
 191 "       str r0, [r1]\n"
 192 "    pop    {r1}\n"
 193 */
 194 
 195 //R3 = Pointer to task function to create
 196 
 197 "    ldr     r0, =task_CaptSeq\n"       // DryOS original code function ptr.
 198 "    cmp     r0, r3\n"                  // is the given taskptr equal to our searched function?
 199 "    itt     eq\n"                      // EQ block
 200 "    ldreq   r3, =capt_seq_task\n"      // if so replace with our task function base ptr.
 201 "    orreq   r3, #1\n"                  // make sure it's a thumb address (may not be needed?)
 202 "    beq     exitHook\n"                // below compares not necessary if this check has found something.
 203 
 204 
 205 "    LDR     R0, =task_ExpDrv\n"
 206 "    CMP     R0, R3\n"
 207 "    itt     eq\n"
 208 "    LDREQ   R3, =exp_drv_task\n"
 209 "    orreq   r3, #1\n"
 210 "    BEQ     exitHook\n"
 211 
 212 /*
 213 "    LDR     R0, =task_DvlpSeq\n"
 214 "    CMP     R0, R3\n"
 215 "    itt     eq\n"
 216 "    LDREQ   R3, =developseq_task\n"
 217 "    orreq   r3, #1\n"
 218 "    BEQ     exitHook\n"
 219 */
 220 
 221 
 222 "    LDR     R0, =task_FileWrite\n"
 223 "    CMP     R0, R3\n"
 224 "    itt     eq\n"
 225 "    LDREQ   R3, =filewritetask\n"
 226 "    orreq   r3, #1\n"
 227 "    BEQ     exitHook\n"
 228 
 229 "    LDR     R0, =0xFC2624ED\n" // TskCocoa0
 230 "    CMP     R0, R3\n"
 231 "    itt     eq\n"
 232 "    LDREQ   R3, =task_cocoa0\n"
 233 "    orreq   r3, #1\n"
 234 "    BEQ     exitHook\n"
 235 
 236 "    LDR     R0, =task_MovieRecord\n"
 237 "    CMP     R0, R3\n"
 238 "    itt     eq\n"
 239 "    LDREQ   R3, =movie_record_task\n"
 240 "    orreq   r3, #1\n"
 241 "    BEQ     exitHook\n"
 242 
 243 "    ldr     r0, =task_InitFileModules\n"
 244 "    cmp     r0, r3\n"
 245 "    itt     eq\n"
 246 "    ldreq   r3, =init_file_modules_task\n"
 247 "    orreq   r3, #1\n"
 248 "exitHook:\n"
 249 
 250 
 251 // restore overwritten register(s)
 252 "    pop    {r0}\n"
 253 // Execute overwritten instructions from original code, then jump to firmware
 254 "    stmdb   sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, lr}\n"
 255 "    mov     r4, r0\n"
 256 "    ldr     r0, =0x8160\n"
 257 "    ldr.w   pc, =(orig_CreateTask + 8) \n"  // Continue in firmware
 258 ".ltorg\n"
 259 );
 260 }
 261 
 262 //fc04f194 ??????????????
 263 void __attribute__((naked,noinline)) sub_fc062f48_my() {
 264 
 265     asm volatile (
 266     "push    {r4, lr}\n"
 267 #if defined(CHDK_NOT_IN_CANON_HEAP)
 268     "ldr     r4, =0x003a7c80\n"         // heap start, modify here
 269 #else
 270     "ldr     r4, =new_sa\n"             // +
 271     "ldr     r4, [r4]\n"                // +
 272 #endif
 273 "                 sub     sp, sp, #0x78\n"
 274 "                 ldr     r0, =0x74e000\n"
 275 "                 ldr     r1, =0x00afd8c\n"
 276 "                 subs    r0, r0, r4\n"
 277 "                 cmp     r0, r1\n"
 278 "                 bcs     loc_fc062f5a\n"
 279 " loc_fc062f58:\n"
 280 "                 b       loc_fc062f58\n"
 281 " loc_fc062f5a:\n"
 282 "                 ldr     r1, =0x8074\n"
 283 "                 mov.w   r0, #0x80000\n"
 284 "                 str     r0, [r1]\n"
 285 "                 ldr     r1, =0x08078\n"
 286 "                 ldr     r0, =0x42a41000\n"
 287 "                 str     r0, [r1]\n"
 288 "                 ldr     r1, =0x0807c\n"
 289 "                 ldr     r0, =0x42a43000\n"
 290 "                 str     r0, [r1]\n"
 291 "                 movs    r1, #0x78\n"
 292 "                 mov     r0, sp\n"
 293 "                 blx     sub_fc302418\n"
 294 "                 ldr     r0, =0x068e000\n"
 295 "                 mov.w   r1, #0xc0000\n"
 296 "                 stmea.w sp, {r0,r1,r4}\n"
 297 "                 ldr     r1, =0x00682274\n"
 298 "                 subs    r2, r1, r4\n"
 299 "                 strd.w  r2, r1, [sp,#0xc]\n"
 300 "                 str     r0, [sp,#0x14]\n"
 301 "                 movs    r0, #0x22\n"
 302 "                 str     r0, [sp,#0x18]\n"
 303 "                 movs    r0, #0x98\n"
 304 "                 str     r0, [sp,#0x1c]\n"
 305 "                 movw    r0, #0x24c\n"
 306 "                 str     r0, [sp,#0x20]\n"
 307 "                 movs    r0, #0xfa\n"
 308 "                 str     r0, [sp,#0x24]\n"
 309 "                 movs    r0, #0xe8\n"
 310 "                 str     r0, [sp,#0x28]\n"
 311 "                 movs    r0, #0x85\n"
 312 "                 str     r0, [sp,#0x2c]\n"
 313 "                 movs    r0, #0x40\n"
 314 "                 str     r0, [sp,#0x30]\n"
 315 "                 movs    r0, #4\n"
 316 "                 str     r0, [sp,#0x34]\n"
 317 "                 movs    r0, #0\n"
 318 "                 str     r0, [sp,#0x38]\n"
 319 "                 movs    r0, #0x10\n"
 320 "                 str     r0, [sp,#0x5c]\n"
 321 "                 movs    r2, #0\n"
 322 "                 lsls    r0, r0, #8\n"
 323 "                 str     r0, [sp,#0x60]\n"
 324 "                 ldr     r1, =sub_fc0630d9_my\n"
 325 "                 asrs    r0, r0, #4\n"
 326 "                 str     r0, [sp,#0x64]\n"
 327 "                 lsls    r0, r0, #5\n"
 328 "                 str     r0, [sp,#0x68]\n"
 329 "                 mov     r0, sp\n"
 330 "                 blx     sub_fc301b7c\n"
 331 "                 add     sp, sp, #0x78\n"
 332 "                 pop     {r4,pc}\n"
 333 
 334     ".ltorg\n"
 335     );
 336 }
 337 
 338 //fc0630d9
 339 void __attribute__((naked,noinline)) sub_fc0630d9_my() {
 340     asm volatile (
 341 "                 push    {r4,lr}\n"
 342 "                 ldr     r4, =0xfc063180\n"
 343 "                 bl      sub_fc0643d4\n"
 344 "                 ldr     r0, =0x000080ec\n"
 345 "                 ldr     r1, [r0]\n"
 346 "                 ldr     r0, =0x00008074\n"
 347 "                 ldr     r0, [r0]\n"
 348 "                 adds    r0, #0x10\n"
 349 "                 cmp     r1, r0\n"
 350 "                 bcs.n     loc_fc0630f4\n"
 351 "                 ldr     r0, =0xfc063190\n"
 352 "                 bl      sub_fc06316a\n"
 353 " loc_fc0630f4:\n"
 354 "                 bl      sub_fc13018c\n"
 355 "                 ldr     r1, =0xbfe10000\n"
 356 "                 mov.w   r2, #0xeeeeeeee\n"
 357 "                 ldr     r3, =0xbfe10800\n"
 358 " loc_fc063100:\n"
 359 "                 stmia   r1!, {r2}\n"
 360 "                 cmp     r1, r3\n"
 361 "                 bcc     loc_fc063100\n"
 362 "                 bl      sub_fc13019e\n"
 363 "                 bl      sub_fc1ede8c\n"
 364 "                 cmp     r0, #0\n"
 365 "                 bge.n     loc_fc063118\n"
 366 "                 ldr     r0, =0xfc0631b0\n"
 367 "                 bl      sub_fc06316a\n"
 368 " loc_fc063118:\n"
 369 "                 bl      sub_fc063964\n"
 370 "                 cmp     r0, #0\n"
 371 "                 bge.n     loc_fc063126\n"
 372 "                 ldr     r0, =0xfc0631b8\n"
 373 "                 bl      sub_fc06316a\n"
 374 " loc_fc063126:\n"
 375 "                 mov     r0, r4\n"
 376 "                 bl      sub_fc0639f2\n"
 377 "                 cmp     r0, #0\n"
 378 "                 bge.n     loc_fc063136\n"
 379 "                 ldr     r0, =0xfc0631c8\n"
 380 "                 bl      sub_fc06316a\n"
 381 " loc_fc063136:\n"
 382 "                 mov     r0, r4\n"
 383 "                 bl      sub_fc063314\n"
 384 "                 cmp     r0, #0\n"
 385 "                 bge.n     loc_fc063146\n"
 386 "                 ldr     r0, =0xfc0631dc\n"
 387 "                 bl      sub_fc06316a\n"
 388 " loc_fc063146:\n"
 389 "                 bl      sub_fc063458\n"
 390 "                 cmp     r0, #0\n"
 391 "                 bge.n     loc_fc063154\n"
 392 "                 ldr     r0, =0xfc0631e8\n"
 393 "                 bl      sub_fc06316a\n"
 394 " loc_fc063154:\n"
 395 "                 bl      sub_fc0665ac\n"
 396 "                 cmp     r0, #0\n"
 397 "                 bge.n     loc_fc063162\n"
 398 "                 ldr     r0, =0xfc0631f4\n"
 399 "                 bl      sub_fc06316a\n"
 400 " loc_fc063162:\n"
 401     "ldmia.w sp!, {r4, lr}\n"
 402     "b.w     sub_fc0634e2_my\n" // -> continue (taskcreate_startup)
 403     ".ltorg\n"
 404     );
 405 }
 406 
 407 void __attribute__((naked,noinline)) sub_fc0634e2_my() {
 408     asm volatile (
 409 "                 push    {r3,lr}\n"
 410 "                 bl      sub_fc0635fc\n"
 411 "                 bl      sub_fc131234\n"
 412 "                 cbnz    r0, loc_fc0634f8\n"
 413 "                 bl      sub_fc07803e\n"
 414 "                 cbz     r0, loc_fc0634f8\n"
 415 "                 movs    r0, #1\n"
 416 "                 b.n       loc_fc0634fa\n"
 417 " loc_fc0634f8:\n"
 418 "                 movs    r0, #0\n"
 419 " loc_fc0634fa:\n"
 420 "                 bl      sub_fc083cc4\n" //_my\n"
 421 "                 cbnz    r0, loc_fc063506\n"
 422 "                 bl      sub_fc0635ea\n"
 423 " loc_fc063504:\n"
 424 "                 b.n       loc_fc063504\n"
 425 " loc_fc063506:\n"
 426 "                 blx     sub_fc301bd4\n"
 427 "                 ldr     r1, =0x74e000\n"
 428 "                 movs    r0, #0\n"
 429 "                 bl      sub_fc37a3e8\n"
 430 "                 blx     sub_fc301fb8\n"
 431 "                 movs    r3, #0\n"
 432 "                 str     r3, [sp,#0]\n"
 433 "                 ldr     r3, =sub_fc06347d_my\n"
 434 "                 movs    r2, #0\n"
 435 "                 movs    r1, #0x19\n"
 436 "                 ldr     r0, =0xfc063534\n"
 437 "                 blx     sub_fc3021b0\n"
 438 "                 movs    r0, #0\n"
 439 "                 pop     {r3,pc}\n"
 440     ".ltorg\n"
 441     );
 442 }
 443 
 444 // task_Startup
 445 void __attribute__((naked,noinline)) sub_fc06347d_my() {
 446 //*(int*)0xd20b0810  = 0x4d0002;
 447     asm volatile (
 448 "                 push    {r4,lr}\n"
 449 "                 bl      sub_fc130f48\n"
 450 "                 bl      sub_fc0635c8\n"
 451 "                 bl      sub_fc06375c\n"
 452 "                 bl      sub_fc0f41f0\n"
 453 //"                 bl      sub_fc0637b2\n"  // - startdiskboot
 454 "                  bl       sub_010e16c8\n" // + Switch off SD power/
 455 "                 bl      sub_fc1ee6da\n"
 456 "                 bl      sub_fc0f4348\n"
 457 "                 bl      sub_fc0638a4\n"
 458 "                 bl      sub_fc0636dc\n"
 459 "                 bl      sub_fc0f4222\n"
 460 "                 bl      sub_fc1ee640\n"
 461 "                 bl      sub_fc0f434e\n"
 462 "                                 bl      CreateTask_spytask\n"  // +
 463 "                 bl      sub_fc083bea_my\n"     // -> taskcreate_physw
 464 "                 bl      sub_fc0a9870\n"
 465 "                 bl      sub_fc0f4364\n"
 466 "                 bl      sub_fc0d2610\n"
 467 "                 bl      sub_fc130d00\n"
 468 "                 bl      sub_fc1310f2\n"
 469 "                 bl      sub_fc0f41a2\n"
 470 "                 bl      sub_fc130cbc\n"
 471 "                 bl      sub_fc0638a8\n"
 472 "                 bl      sub_fc362db4\n"
 473 "                 bl      sub_fc130c90\n"
 474                                 "ldmia.w sp!, {r4, lr}\n"
 475                                 //"                 b.w     sub_fc130f1e\n"      // - (not recognized automatically yet, transformed into ldr pc)
 476                                 "ldr     pc, =0xfc130f1f\n"     // + thumb address must be used
 477                                 ".ltorg\n"
 478     );
 479 }
 480 
 481 //taskcreate_physw
 482 void __attribute__((naked,noinline)) sub_fc083bea_my() {
 483     asm volatile (
 484     "push    {r3, r4, r5, lr}\n"
 485 "                 bl      sub_fc0763a4\n"
 486 "                 bl      sub_fc077fbc\n"
 487 "                 cbnz    r0, loc_fc083bfa\n"
 488 "                 bl      sub_fc076348\n"
 489 " loc_fc083bfa:\n"
 490 "                 ldr     r4, =0x000082cc\n"
 491 "                 ldr     r0, [r4,#4]\n"
 492 "                 cmp     r0, #0\n"
 493 "                 bne.n     locret_fc083c16\n"
 494 "                 movs    r3, #0\n"
 495 "                 str     r3, [sp,#0]\n"
 496 "                 ldr     r3, =mykbd_task\n" //=0xfc083bc5\n"
 497 //"                 ldr     r3, =0xfc083bc5\n" // -orig kbd_task
 498 "                 movs    r1, #0x17\n"
 499 "                 ldr     r0, =0xfc083f2c\n" // "PhySw"
 500 "                 movw    r2, #0x2000\n"         // original value 0x800
 501 "                 blx     sub_fc3022c0\n"
 502 "                 str     r0, [r4,#4]\n"
 503 " locret_fc083c16:\n"
 504                                 "pop     {r3, r4, r5, pc}\n"
 505                                 ".ltorg\n"
 506     );
 507 }
 508 
 509 void __attribute__((naked,noinline)) init_file_modules_task() { //sub_FC0F79A0_my()
 510     asm volatile (
 511 "    push    {r4, r5, r6, lr}\n"
 512 "                 bl      sub_fc0f9dec\n"
 513 "                 movs    r4, r0\n"
 514 "                 movw    r5, #0x5006\n"
 515 "                 beq.n     loc_fc0f79b6\n"
 516 "                 movs    r1, #0\n"
 517 "                 mov     r0, r5\n"
 518 "                 bl      sub_fc37e834\n"
 519 " loc_fc0f79b6:\n"
 520 "                 bl      sub_fc0f9e16\n"
 521 "    BL      core_spytask_can_start\n" // + CHDK: Set "it's-safe-to-start" flag for spytask
 522 "                 cmp     r4, #0\n"
 523 "                 bne.n     loc_fc0f79ca\n"
 524 "                 mov     r0, r5\n"
 525 "    ldmia.w sp!, {r4, r5, r6, lr}\n"
 526 "                 movs    r1, #0\n"
 527 "                 b.w     sub_fc37e834\n"
 528 " loc_fc0f79ca:\n"
 529 "    pop     {r4, r5, r6, pc}\n"
 530     );
 531 }
 532 
 533 void __attribute__((naked,noinline)) kbd_p2_f_my() { // sub_FC083914
 534     asm volatile(
 535 "    stmdb   sp!, {r4, r5, r6, r7, r8, lr}\n"
 536 "                 ldr     r6, =0x520bc\n"
 537 "                 sub     sp, #0x18\n"
 538 "                 add     r7, sp, #8\n"
 539 "                 subs    r6, #0xc\n"
 540 "                 b.n       loc_fc083956\n"
 541 " loc_fc083922:\n"
 542 "                 ldr     r1, =0x520bc\n"
 543 "                 add     r3, sp, #8\n"
 544 "                 ldrb.w  r0, [sp, #4]\n"
 545 "                 add     r2, sp, #0x14\n"
 546 "                 subs    r1, #0x18\n"
 547 "                 bl      sub_fc075420\n"
 548 "                 cbnz    r0, loc_fc08393c\n"
 549 "                 ldr     r1, [sp,#0x14]\n"
 550 "                 movs    r0, #0\n"
 551 "                 bl      sub_fc083886\n"
 552 " loc_fc08393c:\n"
 553 "                 movs    r0, #2\n"
 554 " loc_fc08393e:\n"
 555 "                 ldr.w   r1, [r7, r0, lsl #2]\n"
 556 "                 cbz     r1, loc_fc08394e\n"
 557 "                 ldr.w   r2, [r6, r0, lsl #2]\n"
 558 "                 bics    r2, r1\n"
 559 "                 str.w   r2, [r6, r0, lsl #2]\n"
 560 " loc_fc08394e:\n"
 561 "                 subs    r0, r0, #1\n"
 562 "                 sxtb    r0, r0\n"
 563 "                 cmp     r0, #0\n"
 564 "                 bge.n     loc_fc08393e\n"
 565 " loc_fc083956:\n"
 566 "                 ldr     r0, =0x520bc\n"
 567 "                 add     r1, sp, #0x4\n"
 568 "                 subs    r0, #0xc\n"
 569 "                 bl      sub_fc0750d2\n"
 570 "                 cmp     r0, #0\n"
 571 "                 bne     loc_fc083922\n"
 572 "                 ldr.w   r8, =0x520bc\n"
 573 "                 movs    r4, #0\n"
 574 " loc_fc08396a:\n"
 575 "                 movs    r5, #0\n"
 576 "                 ldr.w   r0, [r6, r4, lsl #2]\n"
 577 "                 ldr.w   r1, [r8, r4, lsl #2]\n"
 578 "                 ands    r0, r1\n"
 579 "                 str.w   r0, [r6, r4, lsl #2]\n"
 580 "                 b.n       loc_fc0839c2\n"
 581 " loc_fc08397c:\n"
 582 "                 lsrs    r0, r5\n"
 583 "                 lsls    r0, r0, #0x1f\n"
 584 "                 beq.n     loc_fc0839ba\n"
 585 "                 ldr     r1, =0x520bc\n"
 586 "                 add.w   r0, r5, r4, lsl #5\n"
 587 "                 add     r3, sp, #0x8\n"
 588 "                 subs    r1, #0x18\n"
 589 "                 add     r2, sp, #0x14\n"
 590 "                 uxtb    r0, r0\n"
 591 "                 bl      sub_fc075420\n"
 592 "                 cbnz    r0, loc_fc08399e\n"
 593 "                 ldr     r1, [sp,#0x14]\n"
 594 "                 movs    r0, #1\n"
 595 "                 bl      sub_fc083886\n"
 596 " loc_fc08399e:\n"
 597 "                 mov     r0, r4\n"
 598 "                 b.n       loc_fc0839b6\n"
 599 " loc_fc0839a2:\n"
 600 "                 ldr.w   r1, [r7, r0, lsl #2]\n"
 601 "                 cbz     r1, loc_fc0839b2\n"
 602 "                 ldr.w   r2, [r6, r0,lsl #2]\n"
 603 "                 bics    r2, r1\n"
 604 "                 str.w   r2, [r6, r0, lsl #2]\n"
 605 " loc_fc0839b2:\n"
 606 "                 adds    r0, r0, #1\n"
 607 "                 sxtb    r0, r0\n"
 608 " loc_fc0839b6:\n"
 609 "                 cmp     r0, #3\n"
 610 "                 blt.n     loc_fc0839a2\n"
 611 " loc_fc0839ba:\n"
 612 "                 ldr.w   r0, [r6, r4, lsl #2]\n"
 613 "                 adds    r5, r5, #1\n"
 614 "                 uxtb    r5, r5\n"
 615 " loc_fc0839c2:\n"
 616 "                 cmp     r0, #0\n"
 617 "                 bne.n     loc_fc08397c\n"
 618 "                 adds    r4, r4, #1\n"
 619 "                 sxtb    r4, r4\n"
 620 "                 cmp     r4, #3\n"
 621 "                 blt.n     loc_fc08396a\n"
 622 "                 bl      sub_fc074e8a_my\n" // ->
 623 "                 add     sp, sp, #0x18\n"
 624 "    ldmia.w sp!, {r4, r5, r6, r7, r8, pc}\n"
 625 ".ltorg\n"
 626     );
 627 }
 628 
 629 void __attribute__((naked,noinline)) sub_fc074e8a_my() {
 630     asm volatile(
 631 "    push    {r4, lr}\n"
 632 "                 ldr     r4, =0x9e50\n"
 633 "                 ldr     r0, [r4,#0x10]\n"
 634 "                 bl      sub_fc0765e4\n"
 635 "                 ldr     r0, [r4,#0x14]\n"
 636 "                 bl      sub_fc07666e\n"
 637 "                 bl      sub_fc0766f6\n"
 638 "                 bl      sub_fc17b250\n"
 639 "                 ldr     r0, [r4,#0x18]\n"
 640 "                 bl      sub_fc076500\n"
 641 "                 ldr     r0, [r4,#0x1c]\n"
 642 "                 bl      sub_fc076500\n"
 643 //"                 pop.w   {r4,lr}\n"       // - (reordered below)
 644 //"                 b.w     sub_fc076948\n"  // - (reordered below)
 645 "    bl      handle_jogdial\n"  // +
 646 "    cmp     r0, #0\n"          // +
 647 "    beq     no_scroll\n"       // +
 648 "                 b.w     sub_fc076948\n"// handles scrollwheel(s), void function, no args
 649 "no_scroll:\n"                  // +
 650 "    pop     {r4, pc}\n"        // +
 651     );
 652 }
 653 
 654 
 655 long __attribute__((naked,noinline)) wrap_kbd_p1_f() {
 656 
 657 asm volatile(
 658 "               push    {r1-r7, lr}\n"
 659 "               movs    r4, #0\n"
 660 "               bl      my_kbd_read_keys\n"
 661 "      ldr     r3, =physw_status\n"
 662 "      movs    r0, #2\n"
 663 "      mov     r5, sp\n"
 664 "      add.w   r6, r3, #0x24\n"
 665 "loc_fc083ebe:\n"
 666 "      add.w   r1, r6, r0,lsl#2\n"
 667 "      ldr.w   r2, [r3,r0,lsl#2]\n"
 668 "      ldr     r7, [r1,#0xc]\n"
 669 "      ldr     r1, [r1,#0x18]\n"
 670 "      and.w   r2, r2, r7\n"
 671 "      eor.w   r2, r2, r1\n"
 672 "      str.w   r2, [r5,r0,lsl#2]\n"
 673 "      subs    r0, r0, #1\n"
 674 "      bpl     loc_fc083ebe\n"
 675 "      ldr     r2, =physw_status\n"
 676 "      mov     r0, sp\n"
 677 "      adds    r2, #0x18\n"
 678 "      sub.w   r1, r2, #0xc\n"
 679 "      bl      sub_fc0839d8_my\n" //kbd_read_keys2\n"
 680 "      ldr     r0, =physw_status\n"
 681 "      adds    r0, #0xc\n"
 682 "      bl      sub_fc074e34\n"
 683 "      cmp     r0, #1\n"
 684 "      bne     loc_fc083ef6\n"
 685 "      movs    r4, #1\n"
 686 "loc_fc083ef6:\n"
 687 "      ldr     r2, =physw_status\n"
 688 "      movs    r0, #2\n"
 689 "      adds    r2, #0x18\n"
 690 "      sub.w   r3, r2, #0xc\n"
 691 "loc_fc083f00:\n"
 692 "      ldr.w   r1, [r2,r0,lsl#2]\n"
 693 "      cbz     r1, loc_fc083f1a\n"
 694 "      ldr.w   r4, [r3,r0,lsl#2]\n"
 695 "      ldr.w   r6, [r5,r0,lsl#2]\n"
 696 "      bics    r4, r1\n"
 697 "      ands    r1, r6\n"
 698 "      orrs    r4, r1\n"
 699 "      str.w   r4, [r3,r0,lsl#2]\n"
 700 "      movs    r4, #1\n"
 701 "loc_fc083f1a:\n"
 702 "      subs    r0, r0, #1\n"
 703 "      bpl     loc_fc083f00\n"
 704 "      mov     r0, r4\n"
 705 "      pop     {r1-r7,pc}\n"
 706 ".ltorg\n"
 707 );
 708 return 0;
 709 }
 710 
 711 void __attribute__((naked,noinline)) sub_fc0839d8_my() {
 712 asm volatile(
 713 "push.w  {r0-r12,lr}\n"
 714 "ldr     r7, =0x520bc\n"
 715 "mov     r5, r0\n"
 716 "mov.w   r0, #0xffffffff\n"
 717 "mov     r9, r1\n"
 718 "str     r0, [sp]\n"
 719 "movs    r0, #2\n"
 720 "adds    r7, #0x24\n"
 721 "mov     r6, r2\n"
 722 "loc_fc0839ee:\n"
 723 "ldr.w   r1, [r5,r0,lsl#2]\n"
 724 "ldr.w   r2, [r9,r0,lsl#2]\n"
 725 "eors    r1, r2\n"
 726 "add.w   r2, r7, r0,lsl#2\n"
 727 "ldr.w   r2, [r2,#0xc0]\n"
 728 "ands    r1, r2\n"
 729 "str.w   r1, [r6,r0,lsl#2]\n"
 730 "subs    r0, r0, #1\n"
 731 "sxtb    r0, r0\n"
 732 "cmp     r0, #0\n"
 733 "bge     loc_fc0839ee\n"
 734 "movs    r0, #2\n"
 735 "loc_fc083a10:\n"
 736 "ldrh    r1, [r7,#0x30]\n"
 737 "add.w   r1, r1, r1,lsl#1\n"
 738 "ldr.w   r2, [r5,r0,lsl#2]\n"
 739 "add.w   r1, r7, r1,lsl#2\n"
 740 "add.w   r1, r1, r0,lsl#2\n"
 741 "subs    r0, r0, #1\n"
 742 "sxtb    r0, r0\n"
 743 "cmp     r0, #0\n"
 744 "str     r2, [r1,#0xc]\n"
 745 "bge     loc_fc083a10\n"
 746 "ldrh    r0, [r7,#0x30]\n"
 747 "mov.w   r12, #0\n"
 748 "adds    r0, r0, #1\n"
 749 "cmp     r0, #3\n"
 750 "bcc     loc_fc083a3e\n"
 751 "strh.w  r12, [r7,#0x30]\n"
 752 "b       loc_fc083a40\n"
 753 "loc_fc083a3e:\n"
 754 "strh    r0, [r7,#0x30]\n"
 755 "loc_fc083a40:\n"
 756 "movs    r0, #2\n"
 757 "loc_fc083a42:\n"
 758 "movs    r2, #0\n"
 759 "mov     r1, r2\n"
 760 "loc_fc083a46:\n"
 761 "add.w   r3, r1, r1,lsl#1\n"
 762 "adds    r1, r1, #1\n"
 763 "add.w   r3, r7, r3,lsl#2\n"
 764 "add.w   r3, r3, r0,lsl#2\n"
 765 "sxtb    r1, r1\n"
 766 "ldr     r4, [r3,#0xc]\n"
 767 "ldr     r3, [r3,#0x18]\n"
 768 "eors    r4, r3\n"
 769 "orrs    r2, r4\n"
 770 "cmp     r1, #2\n"
 771 "blt     loc_fc083a46\n"
 772 "ldr.w   r1, [r5,r0,lsl#2]\n"
 773 "ldr.w   r3, [r9,r0,lsl#2]\n"
 774 "eors    r1, r3\n"
 775 "bics    r1, r2\n"
 776 "ldr.w   r2, [r7,r0,lsl#2]\n"
 777 "ands    r1, r2\n"
 778 "ldr.w   r2, [r6,r0,lsl#2]\n"
 779 "orrs    r1, r2\n"
 780 "str.w   r1, [r6,r0,lsl#2]\n"
 781 "subs    r0, r0, #1\n"
 782 "sxtb    r0, r0\n"
 783 "cmp     r0, #0\n"
 784 "bge     loc_fc083a42\n"
 785 "add.w   r10, sp, #4\n"
 786 "mov.w   r8, #4\n"
 787 "mov     r11, r12\n"
 788 "loc_fc083a90:\n"
 789 "ldr     r3, =0x520bc\n"
 790 "movs    r1, #0\n"
 791 "mov     r12, r10\n"
 792 "movs    r0, #2\n"
 793 "rsb.w   r2, r8, r8,lsl#3\n"
 794 "adds    r3, #0x24\n"
 795 "add.w   r4, r3, r2,lsl#2\n"
 796 "loc_fc083aa2:\n"
 797 "mov     r10, r12\n"
 798 "add.w   r2, r4, r0,lsl#2\n"
 799 "str.w   r11, [r12,r0,lsl#2]\n"
 800 "ldr     r2, [r2,#0x38]\n"
 801 "cbz     r2, loc_fc083ac2\n"
 802 "ldr.w   r3, [r9,r0,lsl#2]\n"
 803 "ldr.w   r7, [r5,r0,lsl#2]\n"
 804 "eors    r3, r7\n"
 805 "ands    r3, r2\n"
 806 "orrs    r1, r3\n"
 807 "str.w   r3, [r10,r0,lsl#2]\n"
 808 "loc_fc083ac2:\n"
 809 "subs    r0, r0, #1\n"
 810 "sxtb    r0, r0\n"
 811 "cmp     r0, #0\n"
 812 "bge     loc_fc083aa2\n"
 813 "cbnz    r1, loc_fc083ad2\n"
 814 "strb.w  r11, [r4,#0x36]\n"
 815 "b       loc_fc083b86\n"
 816 "loc_fc083ad2:\n"
 817 "ldrb.w  r0, [r4,#0x36]\n"
 818 "cbz     r0, loc_fc083afa\n"
 819 "movs    r0, #2\n"
 820 "loc_fc083ada:\n"
 821 "add.w   r1, r4, r0,lsl#2\n"
 822 "ldr.w   r3, [r5,r0,lsl#2]\n"
 823 "ldr     r2, [r1,#0x44]\n"
 824 "ldr     r1, [r1,#0x38]\n"
 825 "eors    r2, r3\n"
 826 "tst     r2, r1\n"
 827 "beq     loc_fc083af2\n"
 828 "strb.w  r11, [r4,#0x36]\n"
 829 "b       loc_fc083afa\n"
 830 "loc_fc083af2:\n"
 831 "subs    r0, r0, #1\n"
 832 "sxtb    r0, r0\n"
 833 "cmp     r0, #0\n"
 834 "bge     loc_fc083ada\n"
 835 "loc_fc083afa:\n"
 836 "add.w   r4, r4, #0x34\n"
 837 "ldrb    r0, [r4,#2]\n"
 838 "add.w   r0, r0, #1\n"
 839 "strb    r0, [r4,#2]\n"
 840 "ldrb.w  r0, [r4],#-0x34\n"
 841 "lsls    r0, r0, #0x18\n"
 842 "bpl     loc_fc083b34\n"
 843 "ldr     r0, [r5]\n"
 844 "ldr     r1, [r4,#0x38]\n"
 845 "ldr     r2, [r4,#0x3c]\n"
 846 "ands    r0, r1\n"
 847 "ldr     r1, [r5,#4]\n"
 848 "ands    r1, r2\n"
 849 "ldr     r2, [r4,#0x40]\n"
 850 "orrs    r0, r1\n"
 851 "ldr     r1, [r5,#8]\n"
 852 "ands    r1, r2\n"
 853 "orrs    r0, r1\n"
 854 "ldrb.w  r0, [r4,#0x35]\n"
 855 "beq     loc_fc083b2e\n"
 856 "lsrs    r7, r0, #4\n"
 857 "b       loc_fc083b38\n"
 858 "loc_fc083b2e:\n"
 859 "and.w   r7, r0, #0xf\n"
 860 "b       loc_fc083b38\n"
 861 "loc_fc083b34:\n"
 862 "ldrsb.w r7, [r4,#0x35]\n"
 863 "loc_fc083b38:\n"
 864 "cmp     r7, #1\n"
 865 "bne     loc_fc083b4a\n"
 866 "ldr     r2, =0x520bc\n"
 867 "add.w   r3, r4, #0x34\n"
 868 "mov     r1, r5\n"
 869 "mov     r0, sp\n"
 870 "bl      sub_fc07507e_my\n" //getkbdstate2\n"
 871 "loc_fc083b4a:\n"
 872 "ldrb.w  r0, [r4,#0x36]\n"
 873 "cmp     r0, r7\n"
 874 "blt     loc_fc083b72\n"
 875 "movs    r0, #2\n"
 876 "mov     r2, r10\n"
 877 "loc_fc083b56:\n"
 878 "ldr.w   r1, [r2,r0,lsl#2]\n"
 879 "cbz     r1, loc_fc083b66\n"
 880 "ldr.w   r3, [r6,r0,lsl#2]\n"
 881 "orrs    r3, r1\n"
 882 "str.w   r3, [r6,r0,lsl#2]\n"
 883 "loc_fc083b66:\n"
 884 "subs    r0, r0, #1\n"
 885 "sxtb    r0, r0\n"
 886 "cmp     r0, #0\n"
 887 "bge     loc_fc083b56\n"
 888 "strb.w  r11, [r4,#0x36]\n"
 889 "loc_fc083b72:\n"
 890 "movs    r0, #2\n"
 891 "loc_fc083b74:\n"
 892 "add.w   r2, r4, r0,lsl#2\n"
 893 "ldr.w   r1, [r5,r0,lsl#2]\n"
 894 "subs    r0, r0, #1\n"
 895 "sxtb    r0, r0\n"
 896 "cmp     r0, #0\n"
 897 "str     r1, [r2,#0x44]\n"
 898 "bge     loc_fc083b74\n"
 899 "loc_fc083b86:\n"
 900 "sub.w   r0, r8, #1\n"
 901 "sxtb.w  r8, r0\n"
 902 "cmp.w   r8, #0\n"
 903 "bge.w   loc_fc083a90\n"
 904 "pop.w   {r0-r12,pc}\n"
 905 ".ltorg\n"
 906 );
 907 }
 908 
 909 
 910 void __attribute__((naked,noinline)) sub_fc07507e_my() {
 911 
 912 extern long kbd_mod_state[];
 913 (void)kbd_mod_state;
 914 asm volatile(
 915 "push    {r4-r8,lr}\n"
 916 "ldr     r4, [r0]\n"
 917 "adds    r4, r4, #1\n"
 918 "bne     loc_fc075090\n"
 919 "ldr     r4, =0xd20bf4a0\n"
 920 "ldr     r4, [r4]\n"
 921 "ldr     r5, =0x43ff9\n"
 922 "ldr     r8, =kbd_mod_state\n"
 923 "ldr     r8, [r8,#4]\n"
 924 "ands    r4, r8\n"
 925 "ands    r4, r5\n"
 926 "str     r4, [r0]\n"
 927 "loc_fc075090:\n"
 928 "movs    r4, #2\n"
 929 "loc_fc075092:\n"
 930 "add.w   r5, r3, r4,lsl#2\n"
 931 "ldr     r5, [r5,#4]\n"
 932 "cbnz    r5, loc_fc07509e\n"
 933 "subs    r4, r4, #1\n"
 934 "bpl     loc_fc075092\n"
 935 "loc_fc07509e:\n"
 936 "ldr     r5, [r0]\n"
 937 "add.w   r0, r2, r4,lsl#2\n"
 938 "add.w   r7, r3, r4,lsl#2\n"
 939 "ldr     r2, [r0,#0xc]\n"
 940 "ldr     r0, [r0,#0x18]\n"
 941 "ands    r5, r2\n"
 942 "ldr.w   r2, [r1,r4,lsl#2]\n"
 943 "eors    r5, r0\n"
 944 "ldr     r0, [r7,#4]\n"
 945 "ands    r5, r0\n"
 946 "and.w   r6, r2, r0\n"
 947 "cmp     r6, r5\n"
 948 "beq     locret_fc0750d0\n"
 949 "ldr     r5, [r7,#0x10]\n"
 950 "bics    r2, r0\n"
 951 "ands    r5, r0\n"
 952 "orrs    r2, r5\n"
 953 "str.w   r2, [r1,r4,lsl#2]\n"
 954 "movs    r0, #0\n"
 955 "strb    r0, [r3,#2]\n"
 956 "locret_fc0750d0:\n"
 957 "pop     {r4-r8,pc}\n"
 958 ".ltorg\n"
 959 );
 960 }
 961 
 962 
 963 

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