root/platform/m10/sub/110d/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. spytask
  2. CreateTask_spytask
  3. boot
  4. CreateTask_my
  5. sub_fc06c500_my
  6. sub_fc06c691_my
  7. sub_fc06ca9a_my
  8. sub_fc06ca35_my
  9. sub_fc0f94ae_my
  10. sub_fc08c4b8_my
  11. init_required_fw_features
  12. support_fi2_boot
  13. sub_fc08c8ee_my
  14. init_file_modules_task
  15. kbd_p2_f_my
  16. sub_fc07eeac_my
  17. kbd_p1_f_cont_my
  18. sub_fc08c6e8_my
  19. task_TricInitTask_my

   1 
   2 #include "lolevel.h"
   3 #include "platform.h"
   4 #include "core.h"
   5 #include "dryos31.h"
   6 #include "cache.h"
   7 
   8 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
   9 
  10 const char * const new_sa = &_end;
  11 
  12 // Forward declarations
  13 extern volatile int jogdial_stopped;
  14 void JogDial_task_my(void);
  15 
  16 extern void task_CaptSeq();
  17 extern void task_InitFileModules();
  18 extern void task_MovieRecord();
  19 extern void task_ExpDrv();
  20 
  21 /*----------------------------------------------------------------------
  22     spytask
  23 -----------------------------------------------------------------------*/
  24 
  25 void spytask(long ua, long ub, long uc, long ud, long ue, long uf)
  26 {
  27     core_spytask();
  28 }
  29 
  30 /*----------------------------------------------------------------------
  31     CreateTask_spytask
  32 -----------------------------------------------------------------------*/
  33 void CreateTask_spytask()
  34 {
  35     _CreateTask("SpyTask", 0x19, 0x2000, spytask, 0);
  36 }
  37 
  38 ///*----------------------------------------------------------------------
  39 // Pointer to stack location where jogdial task records previous and current
  40 // jogdial positions
  41 // short *jog_position;
  42 
  43 /*----------------------------------------------------------------------
  44     boot()
  45 
  46     Main entry point for the CHDK code
  47 -----------------------------------------------------------------------*/
  48 
  49 /*************************************************************/
  50 void __attribute__((naked,noinline)) boot() {
  51     asm volatile ( // 0xfc02000c
  52 "    movw    r0, #0x4000\n"
  53 "    movt    r0, #0\n"
  54 "    mov     sp, r0\n"
  55 "    bl      sub_fc02007e\n"
  56 "    ldr     r2, =0xc0242010\n"
  57 "    ldr     r1, [r2]\n"
  58 "    orr     r1, r1, #1\n"
  59 "    str     r1, [r2]\n"
  60 "    ldr     r0, =0xfceb18d0\n"             // copy (parts of) the DryOS kernel to RAM
  61 "    ldr     r1, =0x010e1000\n"
  62 "    ldr     r3, =0x01107d60\n"
  63 "loc_fc02002a:\n"
  64 "    cmp     r1, r3\n"
  65 "    itt     lo\n"
  66 "    ldrlo   r2, [r0], #4\n"
  67 "    strlo   r2, [r1], #4\n"
  68 "    blo     loc_fc02002a\n"
  69 "    ldr     r0, =0x010e1000\n"
  70 "    ldr     r1, =0x00026d60\n"
  71 "    bl      sub_fc1267ca\n"                // CPU cache operation
  72 "    ldr     r0, =0xfced8630\n"             // copy the rest of DryOS kernel to TCM
  73 "    ldr     r1, =0xbfe10800\n"
  74 "    ldr     r3, =0xbfe1741d\n"
  75 "loc_fc020046:\n"
  76 "    cmp     r1, r3\n"
  77 "    itt     lo\n"
  78 "    ldrlo   r2, [r0], #4\n"
  79 "    strlo   r2, [r1], #4\n"
  80 "    blo     loc_fc020046\n"
  81 
  82 // Install CreateTask patch
  83 // use half words in case source or destination not word aligned
  84         "adr     r0, patch_CreateTask\n"    // src: Patch data
  85         "ldr     r1, =hook_CreateTask\n"    // dest: Address to patch (hook_ has thumb bit off)
  86         "add     r2, r0, #8\n"              // two words
  87 "task_hook_loop:\n"
  88         "ldrh   r3, [r0],#2\n"
  89         "strh   r3, [r1],#2\n"
  90         "cmp    r0,r2\n"
  91         "blo    task_hook_loop\n"
  92 
  93 "    ldr     r0, =0xfce6459c\n"             // copy pre-inited data
  94 "    ldr     r1, =0x00008000\n"
  95 "    ldr     r3, =0x00055334\n"
  96 "loc_fc02005a:\n"
  97 "    cmp     r1, r3\n"
  98 "    itt     lo\n"
  99 "    ldrlo   r2, [r0], #4\n"
 100 "    strlo   r2, [r1], #4\n"
 101 "    blo     loc_fc02005a\n"
 102 "    ldr     r3, =0x00055334\n"             // BSS
 103 "    ldr     r1, =0x003d6ffc\n"
 104 "    mov.w   r2, #0\n"
 105 "loc_fc020070:\n"
 106 "    cmp     r3, r1\n"
 107 "    it      lo\n"
 108 "    strlo   r2, [r3], #4\n"
 109 "    blo     loc_fc020070\n"
 110 "    b.w     sub_fc06c500_my\n"             // ->
 111 
 112 // CreateTask patch, must be aligned as the original
 113         ".align  2\n"
 114 "patch_CreateTask:\n"
 115         "ldr.w   pc, _createtask_my\n"      // Do jump to absolute address CreateTask_my
 116 "_createtask_my:\n"
 117         ".long   CreateTask_my + 1\n"       // has to be a thumb address
 118         ".align  1\n"
 119 
 120 );
 121 }
 122 
 123 /*************************************************************/
 124 void __attribute__((naked,noinline)) CreateTask_my() {
 125 asm volatile (
 126 "    push   {r0}\n"
 127 //R3 = Pointer to task function to create
 128 "    ldr     r0, =task_CaptSeq\n"       // DryOS original code function ptr.
 129 "    cmp     r0, r3\n"                  // is the given taskptr equal to our searched function?
 130 "    itt     eq\n"                      // EQ block
 131 "    ldreq   r3, =capt_seq_task\n"      // if so replace with our task function base ptr.
 132 "    orreq   r3, #1\n"                  // make sure it's a thumb address (may not be needed?)
 133 "    beq     exitHook\n"                // below compares not necessary if this check has found something.
 134 
 135 /*
 136 
 137 "    LDR     R0, =task_ExpDrv\n"
 138 "    CMP     R0, R3\n"
 139 "    itt     eq\n"
 140 "    LDREQ   R3, =exp_drv_task\n"
 141 "    orreq   r3, #1\n"
 142 "    BEQ     exitHook\n"
 143 
 144 "    LDR     R0, =task_DvlpSeqTask\n"
 145 "    CMP     R0, R3\n"
 146 "    itt     eq\n"
 147 "    LDREQ   R3, =developseq_task\n"
 148 "    orreq   r3, #1\n"
 149 "    BEQ     exitHook\n"
 150 
 151 "    LDR     R0, =task_FileWrite\n"
 152 "    CMP     R0, R3\n"
 153 "    itt     eq\n"
 154 "    LDREQ   R3, =filewritetask\n"
 155 "    orreq   r3, #1\n"
 156 "    BEQ     exitHook\n"
 157 */
 158 
 159 "    LDR     R0, =task_TricInitTask\n"
 160 "    CMP     R0, R3\n"
 161 "    itt     eq\n"
 162 "    LDREQ   R3, =task_TricInitTask_my\n"
 163 "    orreq   r3, #1\n"
 164 "    BEQ     exitHook\n"
 165 
 166 "    LDR     R0, =0xFC255E7B\n" // TskCocoa0
 167 "    CMP     R0, R3\n"
 168 "    itt     eq\n"
 169 "    LDREQ   R3, =task_cocoa0\n"
 170 "    orreq   r3, #1\n"
 171 "    BEQ     exitHook\n"
 172 
 173 "    LDR     R0, =task_MovieRecord\n"
 174 "    CMP     R0, R3\n"
 175 "    itt     eq\n"
 176 "    LDREQ   R3, =movie_record_task\n"
 177 "    orreq   r3, #1\n"
 178 "    BEQ     exitHook\n"
 179 
 180 "    ldr     r0, =task_InitFileModules\n"
 181 "    cmp     r0, r3\n"
 182 "    itt     eq\n"
 183 "    ldreq   r3, =init_file_modules_task\n"
 184 "    orreq   r3, #1\n"
 185 "exitHook:\n" 
 186 // restore overwritten register(s)
 187 "    pop    {r0}\n"
 188 // Execute overwritten instructions from original code, then jump to firmware
 189 "    stmdb   sp!, {r1, r2, r3, r4, r5, r6, r7, r8, r9, lr}\n"
 190 "    mov     r4, r0\n"
 191 "    ldr     r0, =0x8160\n"
 192 "    ldr.w   pc, =(hook_CreateTask + 8 + 1) \n"  // Continue in firmware, thumb bit set
 193 ".ltorg\n"
 194 );
 195 }
 196 
 197 void __attribute__((naked,noinline)) sub_fc06c500_my() {
 198     asm volatile (
 199 "    push    {r4, lr}\n"
 200 #if defined(CHDK_NOT_IN_CANON_HEAP)
 201     "ldr     r4, =0x003d6ffc\n"     // heap start, modify here
 202 #else
 203     "ldr     r4, =new_sa\n"         // +
 204     "ldr     r4, [r4]\n"            // +
 205 #endif
 206 "    sub     sp, #0x78\n"
 207 "    ldr     r0, =0x0074e000\n"
 208 "    ldr     r1, =0x000b1fec\n"
 209 "    subs    r0, r0, r4\n"
 210 "    cmp     r0, r1\n"
 211 "    bhs     loc_fc06c512\n"
 212 "loc_fc06c510:\n"
 213 "    b       loc_fc06c510\n"
 214 "loc_fc06c512:\n"
 215 "    ldr     r1, =0x00008074\n"
 216 "    mov.w   r0, #0x80000\n"
 217 "    str     r0, [r1]\n"
 218 "    ldr     r1, =0x00008078\n"
 219 "    ldr     r0, =0x421bcb00\n"
 220 "    str     r0, [r1]\n"
 221 "    ldr     r1, =0x0000807c\n"
 222 "    ldr     r0, =0x421beb00\n"
 223 "    str     r0, [r1]\n"
 224 "    movs    r1, #0x78\n"
 225 "    mov     r0, sp\n"
 226 "    blx     sub_fc314dfc\n"
 227 "    ldr     r0, =0x0068e000\n"
 228 "    mov.w   r1, #0xc0000\n"
 229 "    stm.w   sp, {r0, r1, r4}\n"
 230 "    ldr     r1, =0x00680014\n"
 231 "    subs    r2, r1, r4\n"
 232 "    strd    r2, r1, [sp, #0xc]\n"
 233 "    str     r0, [sp, #0x14]\n"
 234 "    movs    r0, #0x22\n"
 235 "    str     r0, [sp, #0x18]\n"
 236 "    movs    r0, #0xca\n"
 237 "    str     r0, [sp, #0x1c]\n"
 238 "    movw    r0, #0x2b0\n"
 239 "    str     r0, [sp, #0x20]\n"
 240 "    movs    r0, #0xfa\n"
 241 "    str     r0, [sp, #0x24]\n"
 242 "    movw    r0, #0x11a\n"
 243 "    str     r0, [sp, #0x28]\n"
 244 "    movs    r0, #0x85\n"
 245 "    str     r0, [sp, #0x2c]\n"
 246 "    movs    r0, #0x40\n"
 247 "    str     r0, [sp, #0x30]\n"
 248 "    movs    r0, #4\n"
 249 "    str     r0, [sp, #0x34]\n"
 250 "    movs    r0, #0\n"
 251 "    str     r0, [sp, #0x38]\n"
 252 "    movs    r0, #0x10\n"
 253 "    str     r0, [sp, #0x5c]\n"
 254 "    movs    r2, #0\n"
 255 "    lsls    r0, r0, #8\n"
 256 "    str     r0, [sp, #0x60]\n"
 257 "    ldr     r1, =sub_fc06c691_my\n" // ->
 258 "    asrs    r0, r0, #4\n"
 259 "    str     r0, [sp, #0x64]\n"
 260 "    lsls    r0, r0, #5\n"
 261 "    str     r0, [sp, #0x68]\n"
 262 "    mov     r0, sp\n"
 263 "    blx     sub_fc314560\n"
 264 "    add     sp, #0x78\n"
 265 "    pop     {r4, pc}\n"
 266 "    .ltorg\n"
 267     );
 268 }
 269 
 270 void __attribute__((naked,noinline)) sub_fc06c691_my() {
 271     asm volatile (
 272 "    push    {r4, lr}\n"
 273 "    ldr     r4, =0xfc06c738\n"     //  *"/_term"
 274 "    bl      sub_fc06d938\n"
 275 "    ldr     r0, =0x000080ec\n"
 276 "    ldr     r1, [r0]\n"
 277 "    ldr     r0, =0x00008074\n"
 278 "    ldr     r0, [r0]\n"
 279 "    adds    r0, #0x10\n"
 280 "    cmp     r1, r0\n"
 281 "    bhs     loc_fc06c6ac\n"
 282 "    ldr     r0, =0xfc06c748\n"     //  *"USER_MEM size checking"
 283 "    bl      sub_fc06c722\n"
 284 "loc_fc06c6ac:\n"
 285 "    bl      sub_fc1268a4\n"
 286 "    ldr     r1, =0xbfe10000\n"
 287 "    mov.w   r2, #0xeeeeeeee\n"
 288 "    ldr     r3, =0xbfe10800\n"
 289 "loc_fc06c6b8:\n"
 290 "    stm     r1!, {r2}\n"
 291 "    cmp     r1, r3\n"
 292 "    blo     loc_fc06c6b8\n"
 293 "    bl      sub_fc1268b6\n"
 294 "    bl      sub_fc1eb838\n"
 295 "    cmp     r0, #0\n"
 296 "    bge     loc_fc06c6d0\n"
 297 "    ldr     r0, =0xfc06c768\n"     //  *"dmSetup"
 298 "    bl      sub_fc06c722\n"
 299 "loc_fc06c6d0:\n"
 300 "    bl      sub_fc06cedc\n"
 301 "    cmp     r0, #0\n"
 302 "    bge     loc_fc06c6de\n"
 303 "    ldr     r0, =0xfc06c770\n"     //  *"termDriverInit"
 304 "    bl      sub_fc06c722\n"
 305 "loc_fc06c6de:\n"
 306 "    mov     r0, r4\n"
 307 "    bl      sub_fc06cf6a\n"
 308 "    cmp     r0, #0\n"
 309 "    bge     loc_fc06c6ee\n"
 310 "    ldr     r0, =0xfc06c780\n"     //  *"termDeviceCreate"
 311 "    bl      sub_fc06c722\n"
 312 "loc_fc06c6ee:\n"
 313 "    mov     r0, r4\n"
 314 "    bl      sub_fc06c8cc\n"
 315 "    cmp     r0, #0\n"
 316 "    bge     loc_fc06c6fe\n"
 317 "    ldr     r0, =0xfc06c794\n"     //  *"stdioSetup"
 318 "    bl      sub_fc06c722\n"
 319 "loc_fc06c6fe:\n"
 320 "    bl      sub_fc06ca10\n"
 321 "    cmp     r0, #0\n"
 322 "    bge     loc_fc06c70c\n"
 323 "    ldr     r0, =0xfc06c7a0\n"     //  *"stdlibSetup"
 324 "    bl      sub_fc06c722\n"
 325 "loc_fc06c70c:\n"
 326 "    bl      sub_fc1268f8\n"
 327 "    cmp     r0, #0\n"
 328 "    bge     loc_fc06c71a\n"
 329 "    ldr     r0, =0xfc06c7ac\n"     //  *"extlib_setup"
 330 "    bl      sub_fc06c722\n"
 331 "loc_fc06c71a:\n"
 332 "    pop.w   {r4, lr}\n"
 333 "    b.w     sub_fc06ca9a_my\n"     // -> continue (taskcreate_startup)
 334 "    .ltorg\n"
 335     );
 336 }
 337 
 338 void __attribute__((naked,noinline)) sub_fc06ca9a_my() {
 339     asm volatile (
 340 "    push    {r3, lr}\n"
 341 "    bl      sub_fc06cba0\n"        // pxSetup, dhcpc_setup
 342 "    bl      sub_fc07ea92\n"        // IsNormalCameraMode_FW
 343 "    bl      sub_fc08c9c8\n"        // returns 1
 344 "    cbnz    r0, loc_fc06cab0\n"
 345 "    bl      sub_fc06cb8e\n"        // sets GPIO 0x67
 346 "loc_fc06caae:\n"
 347 "    b       loc_fc06caae\n"        // inf. loop
 348 "loc_fc06cab0:\n"
 349 "    blx     sub_fc3145b8\n"        // task related (?)
 350 "    ldr     r1, =0x0074e000\n"
 351 "    movs    r0, #0\n"
 352 "    bl      sub_fc38ccf0\n"        // returns 0
 353 "    movs    r3, #0\n"
 354 "    str     r3, [sp]\n"
 355 "    ldr     r3, =sub_fc06ca35_my\n" //  task_Startup
 356 "    movs    r2, #0\n"
 357 "    movs    r1, #0x19\n"
 358 "    ldr     r0, =0xfc06cad8\n"     //  *"Startup"
 359 "    blx     sub_fc314af4\n"        // j_CreateTask
 360 "    movs    r0, #0\n"
 361 "    pop     {r3, pc}\n"
 362     ".ltorg\n"
 363     );
 364 }
 365 
 366 // task_Startup
 367 void __attribute__((naked,noinline)) sub_fc06ca35_my() {
 368     asm volatile (
 369 "    push    {r4, lr}\n"
 370 "    bl      sub_fc127668\n"        // ... starts clocksave task
 371 "    bl      sub_fc06cb6c\n"        // GPIO, other hw init
 372 "    bl      sub_fc06cccc\n"        // nothing
 373 "    bl      sub_fc0f947c\n"        // HWIC/OC, ... , ADC
 374 //"    bl      sub_fc06cd28\n"      // - startdiskboot
 375 
 376 "    bl      sub_10e173c\n"         // + switch off card, trial
 377 
 378 "    bl      sub_fc37252a\n"        // creates a semaphore
 379 "    bl      sub_fc0f95d4\n"        // cam error related setup
 380 "    bl      sub_fc06ce1c\n"        // writes 0xd601xxxx
 381 "    bl      sub_fc06cc5c\n"        // InitExDrivers
 382 "    bl      sub_fc0f94ae_my\n"     // -> long func, StartWDT, StartSwitchCheck, many others
 383 "    bl      sub_fc1ebfec\n"        // errLogTask, etc...
 384 "    bl      sub_fc0f95da\n"        // UIMemory (600000 bytes), StartEventExchanger, CtrlMan, Autoshut
 385 //"    bl      sub_fc08c8ee\n"      // -
 386 "    bl      sub_fc08c8ee_my\n"     // -> taskcreate_physw
 387 "    bl      CreateTask_spytask\n"  // +
 388 "    bl      init_required_fw_features\n" // +
 389 "    bl      sub_fc2a516e\n"        // SsTask, CaptSeqTask, ...
 390 "    bl      sub_fc0f95f0\n"        // creates a recursive lock
 391 "    bl      sub_fc0d1748\n"        // cobj, ...
 392 "    bl      sub_fc127236\n"        // battery
 393 "    bl      sub_fc127816\n"        // task_Bye
 394 "    bl      sub_fc1275b6\n"        // creates a semaphore (loadtest maybe)
 395 "    bl      sub_fc1271f2\n"        // BatteryTask
 396 "    bl      sub_fc06ce20\n"        // nothing
 397 "    bl      sub_fc3637f4\n"        // PTM_Init, USB CB, create normal or factory mode controller
 398 "    bl      sub_fc1271c6\n"        // ... 11xx levents
 399 "    bl      sut_done \n"           // + CHDK: startuptask (almost) finished - port specific function
 400 "    pop.w   {r4, lr}\n"
 401 "    b.w     sub_fc12763e\n"        // MLHClock
 402     ".ltorg\n"
 403     );
 404 }
 405 
 406 void __attribute__((naked,noinline)) sub_fc0f94ae_my() {
 407     asm volatile (
 408 // capdis -f=chdk -s=0xFC0F94AF -c=26 -stubs PRIMARY.BIN 0xfc000000
 409 "    push    {r4, lr}\n"
 410 "    bl      sub_fc1fb2d0\n"
 411 "    movs    r1, #4\n"
 412 "    movs    r0, #2\n"
 413 "    bl      sub_fc1fabf4\n"
 414 "    bl      sub_fc1fac54\n" // StartWDT_FW
 415 "    bl      sub_fc33e3be\n"
 416 "    bl      sub_fc1fa1b0\n"
 417 "    bl      sub_fc138d8e\n"
 418 "    bl      sub_fc130b44\n"
 419 "    bl      sub_fc131f6c\n"
 420 "    bl      sub_fc08d11c\n" // StartSwitchCheck_FW
 421 "    bl      sub_fc1f36fc\n"
 422 "    bl      sub_fc1f2b7c\n"
 423 "    bl      sub_fc1fae2c\n"
 424 "    ldr     r2, =0x12cea600\n"
 425 "    ldr     r1, =0x7fe8177f\n"
 426 "    blx     sub_fc3145c0\n"
 427 "    bl      sub_fc1f349a\n"
 428 "    bl      sub_fc07eac8\n"
 429 "    bl      sub_fc136fe2\n"
 430 "    bl      sub_fc130a14\n"
 431 "    bl      sub_fc07ea92\n" // IsNormalCameraMode_FW
 432 "    cbz     r0, loc_fc0f9506\n"
 433 "    bl      sub_fc1309bc\n"
 434 "loc_fc0f9506:\n"
 435 "    bl      sub_fc08c4b8_my\n" // ->
 436 "    ldr     pc, =0xFC0F950B\n" // -> continue in fw
 437     );
 438 }
 439 
 440 void __attribute__((naked,noinline)) sub_fc08c4b8_my() {
 441     asm volatile (
 442 // capdis -f=chdk -s=0xFC08C4B9 -c=10 -stubs PRIMARY.BIN 0xfc000000
 443 "    push    {r4, r5, r6, r7, lr}\n"
 444 "    ldr     r6, =0x000082cc\n" //  physw_run
 445 "    sub     sp, #0x84\n"
 446 "    ldr     r0, [r6]\n"
 447 "    cmp     r0, #1\n"
 448 "    beq     sub_fc08c55e\n"    // loc -> sub
 449 "    ldr     r0, =0x00056c10\n"
 450 "    bl      sub_fc07eb8c\n"
 451 "    bl      sub_fc07d624\n"
 452 "    bl      sub_fc07ed70\n"
 453 "bl support_fi2_boot\n"         // +
 454 "    ldr     pc, =0xFC08C4D3\n" // -> continue in fw
 455     );
 456 }
 457 
 458 /*
 459     *** workaround ***
 460     Init stuff to avoid asserts on cameras running DryOS r54+
 461     Execute this only once
 462  */
 463 void init_required_fw_features(void) {
 464     extern int _CreateBinarySemaphore(int, int);
 465 
 466     // aperture related semaphore
 467     *(int*)0x2E804 = _CreateBinarySemaphore(0, 0);
 468     // focuslens related semaphore (may not be needed as sd override does not work)
 469     *(int*)(0x2E7E0+0xC) = _CreateBinarySemaphore(0, 0);
 470 }
 471 
 472 void support_fi2_boot(void) {
 473     // following is for FI2 boot, see sub_FC07ED70
 474     // 0x9bbc stores the reason of startup, which is read from the subcpu
 475     // when booting with fi2, 0x9bbc remains zero, resulting in immediate shutdown
 476     // let's start in playback mode instead
 477     if (*(int*)0x9bbc == 0) *(int*)0x9bbc = 0x8000000; // playback
 478 }
 479 
 480 //taskcreate_physw
 481 void __attribute__((naked,noinline)) sub_fc08c8ee_my() {
 482     asm volatile (
 483 "    push    {r3, r4, r5, lr}\n"
 484 "    bl      sub_fc08029c\n"
 485 "    bl      sub_fc07ea10\n"        // IsFactoryMode_FW
 486 "    cbnz    r0, loc_fc08c8fe\n"
 487 "    bl      sub_fc080240\n"        // OpLog.Start_FW
 488 "loc_fc08c8fe:\n"
 489 "    ldr     r4, =0x000082cc\n"
 490 "    ldr     r0, [r4, #4]\n"
 491 "    cmp     r0, #0\n"
 492 "    bne     loc_fc08c91a\n"
 493 "    movs    r3, #0\n"
 494 "    str     r3, [sp]\n"
 495 "    ldr     r3, =mykbd_task\n"     // original: 0xfc08c8c9, task_PhySw
 496 "    movs    r1, #0x17\n"
 497 "    ldr     r0, =0xfc08cc2c\n"     // *"PhySw"
 498 "    movw    r2, #0x2000\n"         // original: 0x800
 499 "    blx     sub_fc314c8c\n"        // j_CreateTaskStrictly
 500 "    str     r0, [r4, #4]\n"
 501 "loc_fc08c91a:\n"
 502 "    pop     {r3, r4, r5, pc}\n"
 503     ".ltorg\n"
 504     );
 505 }
 506 
 507 void __attribute__((naked,noinline)) init_file_modules_task() {
 508     asm volatile (
 509 // task_InitFileModules 0xfc0d4a01
 510 "    push    {r4, r5, r6, lr}\n"
 511 "    movs    r0, #6\n"
 512 "    bl      sub_fc363042\n"
 513 "    bl      sub_fc138bc0\n"
 514 "    movs    r4, r0\n"
 515 "    movw    r5, #0x5006\n"
 516 "    beq     loc_fc0d4a1c\n"
 517 "    movs    r1, #0\n"
 518 "    mov     r0, r5\n"
 519 "    bl      sub_fc3858fc\n"        // PostLogicalEventToUI_FW
 520 "loc_fc0d4a1c:\n"
 521 "    bl      sub_fc138bea\n"
 522 "    BL      ifm_done\n"            // + CHDK: file modules inited (port specific function)
 523 "    cmp     r4, #0\n"
 524 "    bne     loc_fc0d4a30\n"
 525 "    mov     r0, r5\n"
 526 "    pop.w   {r4, r5, r6, lr}\n"
 527 "    movs    r1, #1\n"
 528 "    b.w     sub_fc3858fc\n"        // PostLogicalEventToUI_FW
 529 "loc_fc0d4a30:\n"
 530 "    pop     {r4, r5, r6, pc}\n"
 531     );
 532 }
 533 
 534 void __attribute__((naked,noinline)) kbd_p2_f_my() {
 535     asm volatile(
 536 // kbd_p2_f 0xfc08c625
 537 "    push.w  {r4, r5, r6, r7, r8, lr}\n"
 538 "    ldr     r6, =0x00056c10\n"
 539 "    sub     sp, #0x18\n"
 540 "    add     r7, sp, #8\n"
 541 "    subs    r6, #0xc\n"
 542 "    b       loc_fc08c666\n"
 543 "loc_fc08c632:\n"
 544 "    ldr     r1, =0x00056c10\n"
 545 "    add     r3, sp, #8\n"
 546 "    ldrb.w  r0, [sp, #4]\n"
 547 "    add     r2, sp, #0x14\n"
 548 "    subs    r1, #0x18\n"
 549 "    bl      sub_fc07f358\n"
 550 "    cbnz    r0, loc_fc08c64c\n"
 551 "    ldr     r1, [sp, #0x14]\n"
 552 "    movs    r0, #0\n"
 553 "    bl      sub_fc08c596\n"
 554 "loc_fc08c64c:\n"
 555 "    movs    r0, #2\n"
 556 "loc_fc08c64e:\n"
 557 "    ldr.w   r1, [r7, r0, lsl #2]\n"
 558 "    cbz     r1, loc_fc08c65e\n"
 559 "    ldr.w   r2, [r6, r0, lsl #2]\n"
 560 "    bics    r2, r1\n"
 561 "    str.w   r2, [r6, r0, lsl #2]\n"
 562 "loc_fc08c65e:\n"
 563 "    subs    r0, r0, #1\n"
 564 "    sxtb    r0, r0\n"
 565 "    cmp     r0, #0\n"
 566 "    bge     loc_fc08c64e\n"
 567 "loc_fc08c666:\n"
 568 "    ldr     r0, =0x00056c10\n"
 569 "    add     r1, sp, #4\n"
 570 "    subs    r0, #0xc\n"
 571 "    bl      sub_fc07f072\n"
 572 "    cmp     r0, #0\n"
 573 "    bne     loc_fc08c632\n"
 574 "    ldr.w   r8, =0x00056c10\n"
 575 "    movs    r4, #0\n"
 576 "loc_fc08c67a:\n"
 577 "    movs    r5, #0\n"
 578 "    ldr.w   r0, [r6, r4, lsl #2]\n"
 579 "    ldr.w   r1, [r8, r4, lsl #2]\n"
 580 "    ands    r0, r1\n"
 581 "    str.w   r0, [r6, r4, lsl #2]\n"
 582 "    b       loc_fc08c6d2\n"
 583 "loc_fc08c68c:\n"
 584 "    lsrs    r0, r5\n"
 585 "    lsls    r0, r0, #0x1f\n"
 586 "    beq     loc_fc08c6ca\n"
 587 "    ldr     r1, =0x00056c10\n"
 588 "    add.w   r0, r5, r4, lsl #5\n"
 589 "    add     r3, sp, #8\n"
 590 "    subs    r1, #0x18\n"
 591 "    add     r2, sp, #0x14\n"
 592 "    uxtb    r0, r0\n"
 593 "    bl      sub_fc07f358\n"
 594 "    cbnz    r0, loc_fc08c6ae\n"
 595 "    ldr     r1, [sp, #0x14]\n"
 596 "    movs    r0, #1\n"
 597 "    bl      sub_fc08c596\n"
 598 "loc_fc08c6ae:\n"
 599 "    mov     r0, r4\n"
 600 "    b       loc_fc08c6c6\n"
 601 "loc_fc08c6b2:\n"
 602 "    ldr.w   r1, [r7, r0, lsl #2]\n"
 603 "    cbz     r1, loc_fc08c6c2\n"
 604 "    ldr.w   r2, [r6, r0, lsl #2]\n"
 605 "    bics    r2, r1\n"
 606 "    str.w   r2, [r6, r0, lsl #2]\n"
 607 "loc_fc08c6c2:\n"
 608 "    adds    r0, r0, #1\n"
 609 "    sxtb    r0, r0\n"
 610 "loc_fc08c6c6:\n"
 611 "    cmp     r0, #3\n"
 612 "    blt     loc_fc08c6b2\n"
 613 "loc_fc08c6ca:\n"
 614 "    ldr.w   r0, [r6, r4, lsl #2]\n"
 615 "    adds    r5, r5, #1\n"
 616 "    uxtb    r5, r5\n"
 617 "loc_fc08c6d2:\n"
 618 "    cmp     r0, #0\n"
 619 "    bne     loc_fc08c68c\n"
 620 "    adds    r4, r4, #1\n"
 621 "    sxtb    r4, r4\n"
 622 "    cmp     r4, #3\n"
 623 "    blt     loc_fc08c67a\n"
 624 "    bl      sub_fc07eeac_my\n"     // ->
 625 "    add     sp, #0x18\n"
 626 "    pop.w   {r4, r5, r6, r7, r8, pc}\n"
 627 ".ltorg\n"
 628     );
 629 }
 630 
 631 void __attribute__((naked,noinline)) sub_fc07eeac_my() {
 632     asm volatile(
 633 "    push    {r4, lr}\n"
 634 "    ldr     r4, =0x00009bd0\n"
 635 "    subs    r4, #0x1c\n"
 636 "    ldr     r0, [r4, #0xc]\n"
 637 "    bl      sub_fc0804c0\n"
 638 "    ldr     r0, [r4, #0x10]\n"
 639 "    bl      sub_fc08054a\n"
 640 "    bl      sub_fc17a004\n"
 641 "    ldr     r0, [r4, #0x14]\n"
 642 "    bl      sub_fc0803f0\n"
 643 //"    pop.w   {r4, lr}\n"          // -
 644 //"    b.w     sub_fc0c3b3c\n"      // -
 645 "    bl      handle_jogdial\n"      // +
 646 "    cmp     r0, #0\n"              // +
 647 "    beq     no_scroll\n"           // +
 648 "    bl      sub_fc0c3b3c\n"        // handles scrollwheel(s), void function, no args
 649 "no_scroll:\n"                      // +
 650 "    pop     {r4, pc}\n"            // +
 651 ".ltorg\n"
 652     );
 653 }
 654 
 655 void __attribute__((naked,noinline)) kbd_p1_f_cont_my() {
 656     asm volatile(
 657 // kbd_p1_f_cont 0xfc08cbb5
 658 "    ldr     r3, =0x00056bec\n"
 659 "    movs    r0, #2\n"
 660 "    mov     r5, sp\n"
 661 "    add.w   r6, r3, #0x24\n"
 662 "loc_fc08cbbe:\n"
 663 "    add.w   r1, r6, r0, lsl #2\n"
 664 "    ldr.w   r2, [r3, r0, lsl #2]\n"
 665 "    ldr     r7, [r1, #0xc]\n"
 666 "    ldr     r1, [r1, #0x18]\n"
 667 "    and.w   r2, r2, r7\n"
 668 "    eor.w   r2, r2, r1\n"
 669 "    str.w   r2, [r5, r0, lsl #2]\n"
 670 "    subs    r0, r0, #1\n"
 671 "    bpl     loc_fc08cbbe\n"
 672 "    bl      xtra_kbd_cb \n"            // +
 673 "    mov     r3, r0 \n"                 // +
 674 "    ldr     r2, =0x00056bec\n"
 675 "    mov     r0, sp\n"
 676 "    adds    r2, #0x18\n"
 677 "    sub.w   r1, r2, #0xc\n"            // 0x56bf8, switchstatus
 678 "    bl      sub_fc08c6e8_my\n"         // -> some physical status is re-read here (not into physw_status)
 679 "    ldr     r0, =0x00056bec\n"
 680 "    adds    r0, #0xc\n"                // 0x56bf8, switchstatus
 681 "    bl      sub_fc07ee60\n"
 682 "    cmp     r0, #1\n"
 683 "    bne     loc_fc08cbf6\n"
 684 "    movs    r4, #1\n"
 685 "loc_fc08cbf6:\n"
 686 "    ldr     r2, =0x00056bec\n"
 687 "    movs    r0, #2\n"
 688 "    adds    r2, #0x18\n"
 689 "    sub.w   r3, r2, #0xc\n"            // 0x56bf8, switchstatus
 690 "loc_fc08cc00:\n"
 691 "    ldr.w   r1, [r2, r0, lsl #2]\n"
 692 "    cbz     r1, loc_fc08cc1a\n"
 693 "    ldr.w   r4, [r3, r0, lsl #2]\n"
 694 "    ldr.w   r6, [r5, r0, lsl #2]\n"
 695 "    bics    r4, r1\n"
 696 "    ands    r1, r6\n"
 697 "    orrs    r4, r1\n"
 698 "    str.w   r4, [r3, r0, lsl #2]\n"
 699 "    movs    r4, #1\n"
 700 "loc_fc08cc1a:\n"
 701 "    subs    r0, r0, #1\n"
 702 "    bpl     loc_fc08cc00\n"
 703 "    mov     r0, r4\n"
 704 "    pop     {r1, r2, r3, r4, r5, r6, r7, pc}\n"
 705     );
 706 }
 707 
 708 void __attribute__((naked,noinline)) sub_fc08c6e8_my() {
 709     asm volatile(
 710 "    push.w  {r0, r1, r2, r3, r4, r5, r6, r7, r8, sb, sl, fp, ip, lr}\n"
 711 "    ldr     r4, =0x00056c10\n"
 712 "    mov     r5, r0\n"
 713 //"    mov.w   r0, #-1\n"               // - should be (physw_status[1] & 0x41fe9) when overriding, -1 otherwise
 714 "    mov     r0, r3 \n"                 // + (new argument to allow passing our variable)
 715 "    b       sub_fc08c6f4\n"            // jump back to ROM
 716     );
 717 }
 718 
 719 
 720 void __attribute__((naked,noinline)) task_TricInitTask_my() {
 721     asm volatile(
 722 // capdis -f=chdk -s=task_TricInitTask -c=35 -stubs PRIMARY.BIN 0xfc000000
 723 // task_TricInitTask 0xfc56075d
 724 "    push.w  {r0, r1, r2, r3, r4, r5, r6, r7, r8, sb, sl, fp, ip, lr}\n"
 725 "    movs    r0, #8\n"
 726 "    ldr     r1, =0xfc560988\n" //  *"InitTskStart"
 727 "    bl      sub_fc37fa52\n"
 728 "    ldr.w   sl, =0x0002e7d8\n"
 729 "    movw    fp, #0x1000\n"
 730 "    ldr     r4, =0x0002e7d4\n"
 731 "    movs    r2, #0\n"
 732 "    ldr     r1, =0x0703870f\n"
 733 "    ldr     r0, [r4]\n"
 734 "    blx     sub_fc314de4\n" // j_WaitForAnyEventFlag
 735 "    lsls    r0, r0, #0x1f\n"
 736 "    beq     loc_fc560792\n"
 737 "    movs    r0, #8\n"
 738 "    ldr     r1, =0xfc5609a0\n" //  *"ER IniTskWait"
 739 "    bl      sub_fc37fab2\n"
 740 "    ldr     r1, =0x0002e7c0\n"
 741 "    movs    r0, #0\n"
 742 "    str     r0, [r1]\n"
 743 "    pop.w   {r0, r1, r2, r3, r4, r5, r6, r7, r8, sb, sl, fp, ip, pc}\n"
 744 "loc_fc560792:\n"
 745 "    ldr     r4, =0x0002e7d4\n"
 746 "    add     r1, sp, #0xc\n"
 747 "    ldr     r0, [r4]\n"
 748 "    blx     sub_fc314b44\n" // j_GetEventFlagValue
 749 "    ldr     r1, [sp, #0xc]\n"
 750 "    ldr     r0, [r4]\n"
 751 "    blx     sub_fc314d3c\n" // j_ClearEventFlag
 752 "    ldr     r0, =0x02000003\n"
 753 "    ldr     r7, [sp, #0xc]\n"
 754 "    tst     r7, r0\n"
 755 "    beq     sub_fc560896\n"    // loc -> sub
 756 "    lsls    r0, r7, #0x1f\n"
 757 "    beq     sub_fc5607b6\n"    // loc -> sub
 758 
 759 "    ldr     r0, =0xd2020074\n" // +
 760 "    ldr     r0, [r0]\n"        // + nonzero when core already running
 761 "    subs    r0, #0\n"          // +
 762 "    beq     tric1\n"           // +
 763 "    ldr     r0, [r4]\n"        // +
 764 "    mov     r1, #0x80\n"       // +
 765 "    bl      _SetEventFlag\n"   // + core already initialized, set the SmacIdleCmp eventflag here
 766 "tric1:\n"                      // +
 767 
 768 "    bl      sub_fc560c3a\n"
 769 "    b       sub_fc560822\n"    // loc -> sub
 770     );
 771 }

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