root/platform/a800/sub/100c/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. taskHook
  2. CreateTask_spytask
  3. boot
  4. sub_FFC0035C_my
  5. sub_FFC011B4_my
  6. sub_FFC05EE4_my
  7. taskcreate_Startup_my
  8. task_Startup_my
  9. taskcreatePhySw_my
  10. init_file_modules_task

   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 extern void task_CaptSeq();
  14 extern void task_InitFileModules();
  15 extern void task_MovieRecord();
  16 extern void task_ExpDrv();
  17 extern void task_FileWrite();
  18 
  19 void taskHook(context_t **context)
  20 {
  21     task_t *tcb=(task_t*)((char*)context-offsetof(task_t, context));
  22 
  23     // Replace firmware task addresses with ours
  24     if(tcb->entry == (void*)task_CaptSeq)          tcb->entry = (void*)capt_seq_task;
  25     if(tcb->entry == (void*)task_InitFileModules)  tcb->entry = (void*)init_file_modules_task;
  26     if(tcb->entry == (void*)task_MovieRecord)      tcb->entry = (void*)movie_record_task;
  27     if(tcb->entry == (void*)task_ExpDrv)           tcb->entry = (void*)exp_drv_task;
  28     if(tcb->entry == (void*)task_FileWrite)        tcb->entry = (void*)filewritetask;
  29 }
  30 
  31 /*----------------------------------------------------------------------
  32     CreateTask_spytask
  33 -----------------------------------------------------------------------*/
  34 void CreateTask_spytask() {
  35     _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);
  36 }
  37 
  38 /*----------------------------------------------------------------------
  39     boot()
  40 
  41     Main entry point for the CHDK code
  42 -----------------------------------------------------------------------*/
  43 
  44 /*************************************************************/
  45 //** boot @ 0xFFC0000C - 0xFFC00160, length=86
  46 void __attribute__((naked,noinline)) boot() {
  47 asm volatile (
  48 "    LDR     R1, =0xC0410000 \n"
  49 "    MOV     R0, #0 \n"
  50 "    STR     R0, [R1] \n"
  51 "    MOV     R1, #0x78 \n"
  52 "    MCR     p15, 0, R1, c1, c0 \n"
  53 "    MOV     R1, #0 \n"
  54 "    MCR     p15, 0, R1, c7, c10, 4 \n"
  55 "    MCR     p15, 0, R1, c7, c5 \n"
  56 "    MCR     p15, 0, R1, c7, c6 \n"
  57 "    MOV     R0, #0x3D \n"
  58 "    MCR     p15, 0, R0, c6, c0 \n"
  59 "    MOV     R0, #0xC000002F \n"
  60 "    MCR     p15, 0, R0, c6, c1 \n"
  61 "    MOV     R0, #0x31 \n"
  62 "    MCR     p15, 0, R0, c6, c2 \n"
  63 "    LDR     R0, =0x10000031 \n"
  64 "    MCR     p15, 0, R0, c6, c3 \n"
  65 "    MOV     R0, #0x40000017 \n"
  66 "    MCR     p15, 0, R0, c6, c4 \n"
  67 "    LDR     R0, =0xFFC0002B \n"
  68 "    MCR     p15, 0, R0, c6, c5 \n"
  69 "    MOV     R0, #0x34 \n"
  70 "    MCR     p15, 0, R0, c2, c0 \n"
  71 "    MOV     R0, #0x34 \n"
  72 "    MCR     p15, 0, R0, c2, c0, 1 \n"
  73 "    MOV     R0, #0x34 \n"
  74 "    MCR     p15, 0, R0, c3, c0 \n"
  75 "    LDR     R0, =0x3333330 \n"
  76 "    MCR     p15, 0, R0, c5, c0, 2 \n"
  77 "    LDR     R0, =0x3333330 \n"
  78 "    MCR     p15, 0, R0, c5, c0, 3 \n"
  79 "    MRC     p15, 0, R0, c1, c0 \n"
  80 "    ORR     R0, R0, #0x1000 \n"
  81 "    ORR     R0, R0, #4 \n"
  82 "    ORR     R0, R0, #1 \n"
  83 "    MCR     p15, 0, R0, c1, c0 \n"
  84 "    MOV     R1, #0x40000006 \n"
  85 "    MCR     p15, 0, R1, c9, c1 \n"
  86 "    MOV     R1, #6 \n"
  87 "    MCR     p15, 0, R1, c9, c1, 1 \n"
  88 "    MRC     p15, 0, R1, c1, c0 \n"
  89 "    ORR     R1, R1, #0x50000 \n"
  90 "    MCR     p15, 0, R1, c1, c0 \n"
  91 "    LDR     R2, =0xC0200000 \n"
  92 "    MOV     R1, #1 \n"
  93 "    STR     R1, [R2, #0x10C] \n"
  94 "    MOV     R1, #0xFF \n"
  95 "    STR     R1, [R2, #0xC] \n"
  96 "    STR     R1, [R2, #0x1C] \n"
  97 "    STR     R1, [R2, #0x2C] \n"
  98 "    STR     R1, [R2, #0x3C] \n"
  99 "    STR     R1, [R2, #0x4C] \n"
 100 "    STR     R1, [R2, #0x5C] \n"
 101 "    STR     R1, [R2, #0x6C] \n"
 102 "    STR     R1, [R2, #0x7C] \n"
 103 "    STR     R1, [R2, #0x8C] \n"
 104 "    STR     R1, [R2, #0x9C] \n"
 105 "    STR     R1, [R2, #0xAC] \n"
 106 "    STR     R1, [R2, #0xBC] \n"
 107 "    STR     R1, [R2, #0xCC] \n"
 108 "    STR     R1, [R2, #0xDC] \n"
 109 "    STR     R1, [R2, #0xEC] \n"
 110 "    STR     R1, [R2, #0xFC] \n"
 111 "    LDR     R1, =0xC0400008 \n"
 112 "    LDR     R2, =0x430005 \n"
 113 "    STR     R2, [R1] \n"
 114 "    MOV     R1, #1 \n"
 115 "    LDR     R2, =0xC0243100 \n"
 116 "    STR     R2, [R1] \n"
 117 "    LDR     R2, =0xC0242010 \n"
 118 "    LDR     R1, [R2] \n"
 119 "    ORR     R1, R1, #1 \n"
 120 "    STR     R1, [R2] \n"
 121 "    LDR     R0, =0xFFF0E280 \n"
 122 "    LDR     R1, =0x1900 \n"
 123 "    LDR     R3, =0xB3C8 \n"
 124 
 125 "loc_FFC0013C:\n"
 126 "    CMP     R1, R3 \n"
 127 "    LDRCC   R2, [R0], #4 \n"
 128 "    STRCC   R2, [R1], #4 \n"
 129 "    BCC     loc_FFC0013C \n"
 130 "    LDR     R1, =0x13A700 \n"
 131 "    MOV     R2, #0 \n"
 132 
 133 "loc_FFC00154:\n"
 134 "    CMP     R3, R1 \n"
 135 "    STRCC   R2, [R3], #4 \n"
 136 "    BCC     loc_FFC00154 \n"
 137 "    B       sub_FFC0035C_my \n"  // --> Patched. Old value = 0xFFC0035C.
 138 );
 139 }
 140 
 141 /*************************************************************/
 142 //** sub_FFC0035C_my @ 0xFFC0035C - 0xFFC003C4, length=27
 143 void __attribute__((naked,noinline)) sub_FFC0035C_my() {
 144 
 145     //http://chdk.setepontos.com/index.php/topic,4194.0.html
 146     *(int*)0x1938=(int)taskHook;
 147     *(int*)0x193C=(int)taskHook;
 148 
 149     // Replacement of sub_FFC4383C for correct power-on.
 150         // A800 ffc4383c <= ffc2396c(Next to NotifyMask) <= ffc10730. Associated Modification in taskcreate_Startup_my
 151     // (short press = playback mode, long press = record mode)
 152         *(int*)(0x20FC)= (*(int*)0xC022005C) & 1 ? 0x200000 : 0x100000; 
 153 
 154 asm volatile (
 155 "    LDR     R0, =0xFFC003D4 \n"
 156 "    MOV     R1, #0 \n"
 157 "    LDR     R3, =0xFFC0040C \n"
 158 
 159 "loc_FFC00368:\n"
 160 "    CMP     R0, R3 \n"
 161 "    LDRCC   R2, [R0], #4 \n"
 162 "    STRCC   R2, [R1], #4 \n"
 163 "    BCC     loc_FFC00368 \n"
 164 "    LDR     R0, =0xFFC0040C \n"
 165 "    MOV     R1, #0x4B0 \n"
 166 "    LDR     R3, =0xFFC00620 \n"
 167 
 168 "loc_FFC00384:\n"
 169 "    CMP     R0, R3 \n"
 170 "    LDRCC   R2, [R0], #4 \n"
 171 "    STRCC   R2, [R1], #4 \n"
 172 "    BCC     loc_FFC00384 \n"
 173 "    MOV     R0, #0xD2 \n"
 174 "    MSR     CPSR_cxsf, R0 \n"
 175 "    MOV     SP, #0x1000 \n"
 176 "    MOV     R0, #0xD3 \n"
 177 "    MSR     CPSR_cxsf, R0 \n"
 178 "    MOV     SP, #0x1000 \n"
 179 "    LDR     R0, =0x6C4 \n"
 180 "    LDR     R2, =0xEEEEEEEE \n"
 181 "    MOV     R3, #0x1000 \n"
 182 
 183 "loc_FFC003B8:\n"
 184 "    CMP     R0, R3 \n"
 185 "    STRCC   R2, [R0], #4 \n"
 186 "    BCC     loc_FFC003B8 \n"
 187 "    BL      sub_FFC011B4_my \n"  // --> Patched. Old value = 0xFFC011B4.
 188 );
 189 }
 190 
 191 /*************************************************************/
 192 //** sub_FFC011B4_my @ 0xFFC011B4 - 0xFFC01260, length=44
 193 void __attribute__((naked,noinline)) sub_FFC011B4_my() {
 194 asm volatile (
 195 "    STR     LR, [SP, #-4]! \n"
 196 "    SUB     SP, SP, #0x74 \n"
 197 "    MOV     R1, #0x74 \n"
 198 "    MOV     R0, SP \n"
 199 "    BL      sub_FFE99B50 \n"
 200 "    MOV     R0, #0x53000 \n"
 201 "    STR     R0, [SP, #4] \n"
 202 
 203 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 204 "    LDR     R0, =0x13A700 \n"
 205 #else
 206 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 207 "    LDR     R0, [R0]\n"      //
 208 #endif
 209 
 210 "    LDR     R2, =0x271F80 \n"
 211 "    STR     R0, [SP, #8] \n"
 212 "    SUB     R0, R2, R0 \n"
 213 "    STR     R0, [SP, #0xC] \n"
 214 "    MOV     R0, #0x22 \n"
 215 "    STR     R0, [SP, #0x18] \n"
 216 "    MOV     R0, #0x68 \n"
 217 "    STR     R0, [SP, #0x1C] \n"
 218 "    LDR     R1, =0x279C00 \n"
 219 "    LDR     R0, =0x19B \n"
 220 "    STR     R1, [SP] \n"
 221 "    STR     R0, [SP, #0x20] \n"
 222 "    MOV     R0, #0x96 \n"
 223 "    STR     R2, [SP, #0x10] \n"
 224 "    STR     R1, [SP, #0x14] \n"
 225 "    STR     R0, [SP, #0x24] \n"
 226 "    STR     R0, [SP, #0x28] \n"
 227 "    MOV     R0, #0x64 \n"
 228 "    STR     R0, [SP, #0x2C] \n"
 229 "    MOV     R0, #0 \n"
 230 "    STR     R0, [SP, #0x30] \n"
 231 "    STR     R0, [SP, #0x34] \n"
 232 "    MOV     R0, #0x10 \n"
 233 "    STR     R0, [SP, #0x5C] \n"
 234 "    MOV     R0, #0x800 \n"
 235 "    STR     R0, [SP, #0x60] \n"
 236 "    MOV     R0, #0xA0 \n"
 237 "    STR     R0, [SP, #0x64] \n"
 238 "    MOV     R0, #0x280 \n"
 239 "    STR     R0, [SP, #0x68] \n"
 240 "    LDR     R1, =sub_FFC05EE4_my \n"  // --> Patched. Old value = 0xFFC05EE4.
 241 "    MOV     R2, #0 \n"
 242 "    MOV     R0, SP \n"
 243 "    BL      sub_FFC034C8 \n"
 244 "    ADD     SP, SP, #0x74 \n"
 245 "    LDR     PC, [SP], #4 \n"
 246 );
 247 }
 248 
 249 /*************************************************************/
 250 //** sub_FFC05EE4_my @ 0xFFC05EE4 - 0xFFC05F58, length=30
 251 void __attribute__((naked,noinline)) sub_FFC05EE4_my() {
 252 asm volatile (
 253 "    STMFD   SP!, {R4,LR} \n"
 254 "    BL      sub_FFC00B2C \n"
 255 "    BL      sub_FFC0A978 \n"
 256 "    CMP     R0, #0 \n"
 257 "    LDRLT   R0, =0xFFC05FF8 /*'dmSetup'*/ \n"
 258 "    BLLT    _err_init_task \n"
 259 "    BL      sub_FFC05B1C \n"
 260 "    CMP     R0, #0 \n"
 261 "    LDRLT   R0, =0xFFC06000 /*'termDriverInit'*/ \n"
 262 "    BLLT    _err_init_task \n"
 263 "    LDR     R0, =0xFFC06010 /*'/_term'*/ \n"
 264 "    BL      sub_FFC05C04 \n"
 265 "    CMP     R0, #0 \n"
 266 "    LDRLT   R0, =0xFFC06018 /*'termDeviceCreate'*/ \n"
 267 "    BLLT    _err_init_task \n"
 268 "    LDR     R0, =0xFFC06010 /*'/_term'*/ \n"
 269 "    BL      sub_FFC03CAC \n"
 270 "    CMP     R0, #0 \n"
 271 "    LDRLT   R0, =0xFFC0602C /*'stdioSetup'*/ \n"
 272 "    BLLT    _err_init_task \n"
 273 "    BL      sub_FFC0A304 \n"
 274 "    CMP     R0, #0 \n"
 275 "    LDRLT   R0, =0xFFC06038 /*'stdlibSetup'*/ \n"
 276 "    BLLT    _err_init_task \n"
 277 "    BL      sub_FFC01694 \n"
 278 "    CMP     R0, #0 \n"
 279 "    LDRLT   R0, =0xFFC06044 /*'armlib_setup'*/ \n"
 280 "    BLLT    _err_init_task \n"
 281 "    LDMFD   SP!, {R4,LR} \n"
 282 "    B       taskcreate_Startup_my \n"  // --> Patched. Old value = 0xFFC10730.
 283 );
 284 }
 285 
 286 /*************************************************************/
 287 //** taskcreate_Startup_my @ 0xFFC10730 - 0xFFC107EC, length=48
 288 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 289 asm volatile (
 290 "    STMFD   SP!, {R3-R9,LR} \n"
 291 "    MOV     R6, #0 \n"
 292 //"  BL      _sub_FFC43834 \n"  // --> Nullsub call removed.
 293 "    BL      sub_FFC2B1CC \n"
 294 "    LDR     R9, =0xC0220000 \n"
 295 "    MOVS    R7, R0 \n"
 296 "    MOV     R8, #1 \n"
 297 "    BNE     loc_FFC10790 \n"
 298 "    BL      sub_FFC25268 /*_IsNormalCameraMode_FW*/ \n"
 299 "    CMP     R0, #0 \n"
 300 "    BEQ     loc_FFC10790 \n"
 301 "    LDR     R0, [R9, #0x44] \n"
 302 "    BIC     R5, R8, R0 \n"
 303 "    LDR     R0, [R9, #0x5C] \n"
 304 "    BIC     R4, R8, R0 \n"
 305 "    BL      sub_FFC232AC \n"
 306 "    CMP     R0, #1 \n"
 307 "    MOVEQ   R6, #1 \n"
 308 "    ORR     R0, R4, R5 \n"
 309 "    ORRS    R0, R0, R6 \n"
 310 "    BNE     loc_FFC107A0 \n"
 311 "    MOV     R0, #0x44 \n"
 312 "    STR     R0, [R9, #0x20] \n"
 313 
 314 "loc_FFC1078C:\n"
 315 "    B       loc_FFC1078C \n"
 316 
 317 "loc_FFC10790:\n"
 318 "    LDR     R0, [R9, #0x5C] \n"
 319 "    BIC     R4, R8, R0 \n"
 320 "    LDR     R0, [R9, #0x44] \n"
 321 "    BIC     R5, R8, R0 \n"
 322 
 323 "loc_FFC107A0:\n"
 324 "    MOV     R3, R6 \n"
 325 "    MOV     R2, R7 \n"
 326 "    MOV     R1, R5 \n"
 327 "    MOV     R0, R4 \n"
 328 //"  BL      _sub_FFC4383C \n"  // StartUp mode detection. We must remove this for power-on mode handling to work
 329 //"  BL      _sub_FFC43838 \n"  // --> Nullsub call removed.
 330 "    BL      sub_FFC29590 \n"
 331 "    LDR     R1, =0x2CE000 \n"
 332 "    MOV     R0, #0 \n"
 333 "    BL      sub_FFC29800 \n"
 334 "    BL      sub_FFC297A8 \n"
 335 "    MOV     R3, #0 \n"
 336 "    STR     R3, [SP] \n"
 337 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFFC106D4.
 338 "    MOV     R2, #0 \n"
 339 "    MOV     R1, #0x19 \n"
 340 "    LDR     R0, =0xFFC107FC /*'Startup'*/ \n"
 341 "    BL      _CreateTask \n"
 342 "    MOV     R0, #0 \n"
 343 "    LDMFD   SP!, {R3-R9,PC} \n"
 344 );
 345 }
 346 
 347 /*************************************************************/
 348 //** task_Startup_my @ 0xFFC106D4 - 0xFFC1072C, length=23
 349 void __attribute__((naked,noinline)) task_Startup_my() {
 350 asm volatile (
 351 "    STMFD   SP!, {R4,LR} \n"
 352 "    BL      sub_FFC062B0 \n"
 353 "    BL      sub_FFC24AD8 \n"
 354 "    BL      sub_FFC232BC \n"
 355 //"  BL      _sub_FFC43EB0 \n"  // --> Nullsub call removed.
 356 "    BL      sub_FFC2B400 \n"
 357 //"  BL      _sub_FFC2B2A8 \n"  // start diskboot.bin
 358 "    BL      sub_FFC704D4 \n"
 359 "    BL      sub_FFC2B430 \n"
 360 "    BL      sub_FFC28A24 \n"
 361 "    BL      sub_FFC2B5A0 \n"
 362 "    BL      CreateTask_spytask\n"  // added
 363 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFFC2382C.
 364 "    LDR     PC, =0xFFC10704 \n"  // Continue in firmware
 365 );
 366 }
 367 
 368 /*************************************************************/
 369 //** taskcreatePhySw_my @ 0xFFC2382C - 0xFFC2384C, length=9
 370 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 371 asm volatile (
 372 "    STMFD   SP!, {R3-R5,LR} \n"
 373 "    LDR     R4, =0x1BF8 \n"
 374 "    LDR     R0, [R4, #4] \n"
 375 "    CMP     R0, #0 \n"
 376 "    BNE     sub_FFC23860 \n"
 377 "    MOV     R3, #0 \n"
 378 "    STR     R3, [SP] \n"
 379 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFFC237F8.
 380 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw
 381 "    LDR     PC, =0xFFC23850 \n"  // Continue in firmware
 382 );
 383 }
 384 
 385 /*************************************************************/
 386 //** init_file_modules_task @ 0xFFC7387C - 0xFFC73898, length=8
 387 void __attribute__((naked,noinline)) init_file_modules_task() {
 388 asm volatile (
 389 "    STMFD   SP!, {R4-R6,LR} \n"
 390 "    BL      sub_FFC6C2C0 \n"
 391 "    LDR     R5, =0x5006 \n"
 392 "    MOVS    R4, R0 \n"
 393 "    MOVNE   R1, #0 \n"
 394 "    MOVNE   R0, R5 \n"
 395 "    BLNE    _PostLogicalEventToUI \n"
 396 "    BL      sub_FFC6C2EC \n"
 397 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 398 "    LDR     PC, =0xFFC7389C \n"  // Continue in firmware
 399 );
 400 }

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