root/platform/a2200/sub/100d/boot.c

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

DEFINITIONS

This source file includes following definitions.
  1. taskHook
  2. CreateTask_spytask
  3. boot
  4. sub_FF810358_my
  5. sub_FF8111B0_my
  6. sub_FF815EE0_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 @ 0xFF81000C - 0xFF810160, 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, #0x33 \n"
  62 "    MCR     p15, 0, R0, c6, c2 \n"
  63 "    MOV     R0, #0x40000033 \n"
  64 "    MCR     p15, 0, R0, c6, c3 \n"
  65 "    MOV     R0, #0x80000017 \n"
  66 "    MCR     p15, 0, R0, c6, c4 \n"
  67 "    LDR     R0, =0xFF80002D \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, #0x80000006 \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, =0xFFC29E9C \n"
 122 "    LDR     R1, =0x1900 \n"
 123 "    LDR     R3, =0xECB4 \n"
 124 
 125 "loc_FF81013C:\n"
 126 "    CMP     R1, R3 \n"
 127 "    LDRCC   R2, [R0], #4 \n"
 128 "    STRCC   R2, [R1], #4 \n"
 129 "    BCC     loc_FF81013C \n"
 130 "    LDR     R1, =0x1698CC \n"
 131 "    MOV     R2, #0 \n"
 132 
 133 "loc_FF810154:\n"
 134 "    CMP     R3, R1 \n"
 135 "    STRCC   R2, [R3], #4 \n"
 136 "    BCC     loc_FF810154 \n"
 137 "    B       sub_FF810358_my \n"  // --> Patched. Old value = 0xFF810358.
 138 );
 139 }
 140 
 141 /*************************************************************/
 142 //** sub_FF810358_my @ 0xFF810358 - 0xFF8103C0, length=27
 143 void __attribute__((naked,noinline)) sub_FF810358_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_FF85FC4C (sub_FF834388) for correct power-on.
 150     // (short press = playback mode, long press = record mode)
 151     *(int*)(0x24F8) = (*(int*)0xC0220064)&1 ? 0x200000 : 0x100000;
 152 
 153 asm volatile (
 154 "    LDR     R0, =0xFF8103D0 \n"
 155 "    MOV     R1, #0 \n"
 156 "    LDR     R3, =0xFF810408 \n"
 157 
 158 "loc_FF810364:\n"
 159 "    CMP     R0, R3 \n"
 160 "    LDRCC   R2, [R0], #4 \n"
 161 "    STRCC   R2, [R1], #4 \n"
 162 "    BCC     loc_FF810364 \n"
 163 "    LDR     R0, =0xFF810408 \n"
 164 "    MOV     R1, #0x4B0 \n"
 165 "    LDR     R3, =0xFF81061C \n"
 166 
 167 "loc_FF810380:\n"
 168 "    CMP     R0, R3 \n"
 169 "    LDRCC   R2, [R0], #4 \n"
 170 "    STRCC   R2, [R1], #4 \n"
 171 "    BCC     loc_FF810380 \n"
 172 "    MOV     R0, #0xD2 \n"
 173 "    MSR     CPSR_cxsf, R0 \n"
 174 "    MOV     SP, #0x1000 \n"
 175 "    MOV     R0, #0xD3 \n"
 176 "    MSR     CPSR_cxsf, R0 \n"
 177 "    MOV     SP, #0x1000 \n"
 178 "    LDR     R0, =0x6C4 \n"
 179 "    LDR     R2, =0xEEEEEEEE \n"
 180 "    MOV     R3, #0x1000 \n"
 181 
 182 "loc_FF8103B4:\n"
 183 "    CMP     R0, R3 \n"
 184 "    STRCC   R2, [R0], #4 \n"
 185 "    BCC     loc_FF8103B4 \n"
 186 "    BL      sub_FF8111B0_my \n"  // --> Patched. Old value = 0xFF8111B0.
 187 );
 188 }
 189 
 190 /*************************************************************/
 191 //** sub_FF8111B0_my @ 0xFF8111B0 - 0xFF81125C, length=44
 192 void __attribute__((naked,noinline)) sub_FF8111B0_my() {
 193 asm volatile (
 194 "    STR     LR, [SP, #-4]! \n"
 195 "    SUB     SP, SP, #0x74 \n"
 196 "    MOV     R1, #0x74 \n"
 197 "    MOV     R0, SP \n"
 198 "    BL      sub_FFB51098 \n"
 199 "    MOV     R0, #0x53000 \n"
 200 "    STR     R0, [SP, #4] \n"
 201 
 202 #if defined(CHDK_NOT_IN_CANON_HEAP) // use original heap offset if CHDK is loaded in high memory
 203 "    LDR     R0, =0x1698CC \n"
 204 #else
 205 "    LDR     R0, =new_sa\n"   // otherwise use patched value
 206 "    LDR     R0, [R0]\n"      //
 207 #endif
 208 
 209 "    LDR     R2, =0x2F1F80 \n"
 210 "    STR     R0, [SP, #8] \n"
 211 "    SUB     R0, R2, R0 \n"
 212 "    STR     R0, [SP, #0xC] \n"
 213 "    MOV     R0, #0x22 \n"
 214 "    STR     R0, [SP, #0x18] \n"
 215 "    MOV     R0, #0x68 \n"
 216 "    STR     R0, [SP, #0x1C] \n"
 217 "    LDR     R1, =0x2F9C00 \n"
 218 "    LDR     R0, =0x19B \n"
 219 "    STR     R1, [SP] \n"
 220 "    STR     R0, [SP, #0x20] \n"
 221 "    MOV     R0, #0x96 \n"
 222 "    STR     R2, [SP, #0x10] \n"
 223 "    STR     R1, [SP, #0x14] \n"
 224 "    STR     R0, [SP, #0x24] \n"
 225 "    STR     R0, [SP, #0x28] \n"
 226 "    MOV     R0, #0x64 \n"
 227 "    STR     R0, [SP, #0x2C] \n"
 228 "    MOV     R0, #0 \n"
 229 "    STR     R0, [SP, #0x30] \n"
 230 "    STR     R0, [SP, #0x34] \n"
 231 "    MOV     R0, #0x10 \n"
 232 "    STR     R0, [SP, #0x5C] \n"
 233 "    MOV     R0, #0x800 \n"
 234 "    STR     R0, [SP, #0x60] \n"
 235 "    MOV     R0, #0xA0 \n"
 236 "    STR     R0, [SP, #0x64] \n"
 237 "    MOV     R0, #0x280 \n"
 238 "    STR     R0, [SP, #0x68] \n"
 239 "    LDR     R1, =sub_FF815EE0_my \n"  // --> Patched. Old value = 0xFF815EE0.
 240 "    MOV     R2, #0 \n"
 241 "    MOV     R0, SP \n"
 242 "    BL      sub_FF8134C4 \n"
 243 "    ADD     SP, SP, #0x74 \n"
 244 "    LDR     PC, [SP], #4 \n"
 245 );
 246 }
 247 
 248 /*************************************************************/
 249 //** sub_FF815EE0_my @ 0xFF815EE0 - 0xFF815F54, length=30
 250 void __attribute__((naked,noinline)) sub_FF815EE0_my() {
 251 asm volatile (
 252 "    STMFD   SP!, {R4,LR} \n"
 253 "    BL      sub_FF810B28 \n"
 254 "    BL      sub_FF81A374 \n"
 255 "    CMP     R0, #0 \n"
 256 "    LDRLT   R0, =0xFF815FF4 /*'dmSetup'*/ \n"
 257 "    BLLT    _err_init_task \n"
 258 "    BL      sub_FF815B18 \n"
 259 "    CMP     R0, #0 \n"
 260 "    LDRLT   R0, =0xFF815FFC /*'termDriverInit'*/ \n"
 261 "    BLLT    _err_init_task \n"
 262 "    LDR     R0, =0xFF81600C /*'/_term'*/ \n"
 263 "    BL      sub_FF815C00 \n"
 264 "    CMP     R0, #0 \n"
 265 "    LDRLT   R0, =0xFF816014 /*'termDeviceCreate'*/ \n"
 266 "    BLLT    _err_init_task \n"
 267 "    LDR     R0, =0xFF81600C /*'/_term'*/ \n"
 268 "    BL      sub_FF813CA8 \n"
 269 "    CMP     R0, #0 \n"
 270 "    LDRLT   R0, =0xFF816028 /*'stdioSetup'*/ \n"
 271 "    BLLT    _err_init_task \n"
 272 "    BL      sub_FF819D00 \n"
 273 "    CMP     R0, #0 \n"
 274 "    LDRLT   R0, =0xFF816034 /*'stdlibSetup'*/ \n"
 275 "    BLLT    _err_init_task \n"
 276 "    BL      sub_FF811690 \n"
 277 "    CMP     R0, #0 \n"
 278 "    LDRLT   R0, =0xFF816040 /*'armlib_setup'*/ \n"
 279 "    BLLT    _err_init_task \n"
 280 "    LDMFD   SP!, {R4,LR} \n"
 281 "    B       taskcreate_Startup_my \n"  // --> Patched. Old value = 0xFF81FC58.
 282 );
 283 }
 284 
 285 /*************************************************************/
 286 //** taskcreate_Startup_my @ 0xFF81FC58 - 0xFF81FD1C, length=50
 287 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 288 asm volatile (
 289 "    STMFD   SP!, {R3-R9,LR} \n"
 290 "    MOV     R6, #0 \n"
 291 //"  BL      _sub_FF85FC44 \n"  // --> Nullsub call removed.
 292 "    BL      sub_FF83BF64 \n"
 293 "    LDR     R9, =0xC0220000 \n"
 294 "    MOVS    R7, R0 \n"
 295 "    MOV     R8, #1 \n"
 296 "    BNE     loc_FF81FCC0 \n"
 297 "    BL      sub_FF835C84 /*_IsNormalCameraMode_FW*/ \n"
 298 "    CMP     R0, #0 \n"
 299 "    BEQ     loc_FF81FCC0 \n"
 300 "    LDR     R0, [R9, #0x60] \n"
 301 "    BIC     R5, R8, R0 \n"
 302 "    LDR     R0, [R9, #0x64] \n"
 303 "    BIC     R4, R8, R0 \n"
 304 "    BL      sub_FF83363C \n"
 305 "    CMP     R0, #1 \n"
 306 "    MOVEQ   R6, #1 \n"
 307 "    ORR     R0, R4, R5 \n"
 308 "    ORRS    R0, R0, R6 \n"
 309 "    BNE     loc_FF81FCD0 \n"
 310 "    BL      sub_FF833A00 \n"
 311 "    MOV     R0, #0x44 \n"
 312 "    STR     R0, [R9, #0x1C] \n"
 313 "    BL      sub_FF833BEC \n"
 314 
 315 "loc_FF81FCBC:\n"
 316 "    B       loc_FF81FCBC \n"
 317 
 318 "loc_FF81FCC0:\n"
 319 "    LDR     R0, [R9, #0x64] \n"
 320 "    BIC     R4, R8, R0 \n"
 321 "    LDR     R0, [R9, #0x60] \n"
 322 "    BIC     R5, R8, R0 \n"
 323 
 324 "loc_FF81FCD0:\n"
 325 "    MOV     R3, R6 \n"
 326 "    MOV     R2, R7 \n"
 327 "    MOV     R1, R5 \n"
 328 "    MOV     R0, R4 \n"
 329 //"  BL      _sub_FF85FC4C \n"  // StartUp mode detection. We must remove this for power-on mode handling to work
 330 //"  BL      _sub_FF85FC48 \n"  // --> Nullsub call removed.
 331 "    BL      sub_FF83A134 \n"
 332 "    LDR     R1, =0x34E000 \n"
 333 "    MOV     R0, #0 \n"
 334 "    BL      sub_FF83A5A4 \n"
 335 "    BL      sub_FF83A34C \n"
 336 "    MOV     R3, #0 \n"
 337 "    STR     R3, [SP] \n"
 338 "    LDR     R3, =task_Startup_my \n"  // --> Patched. Old value = 0xFF81FBF4.
 339 "    MOV     R2, #0 \n"
 340 "    MOV     R1, #0x19 \n"
 341 "    LDR     R0, =0xFF81FD2C /*'Startup'*/ \n"
 342 "    BL      _CreateTask \n"
 343 "    MOV     R0, #0 \n"
 344 "    LDMFD   SP!, {R3-R9,PC} \n"
 345 );
 346 }
 347 
 348 /*************************************************************/
 349 //** task_Startup_my @ 0xFF81FBF4 - 0xFF81FC4C, length=23
 350 void __attribute__((naked,noinline)) task_Startup_my() {
 351 asm volatile (
 352 "    STMFD   SP!, {R4,LR} \n"
 353 "    BL      sub_FF816588 \n"
 354 "    BL      sub_FF8354F4 \n"
 355 "    BL      sub_FF83364C \n"
 356 //"  BL      _sub_FF8602F8 \n"  // --> Nullsub call removed.
 357 "    BL      sub_FF83C198 \n"
 358 //"  BL      _sub_FF83C040 \n"  // start diskboot.bin
 359 "    BL      sub_FF88FC20 \n"
 360 "    BL      sub_FF832208 \n"
 361 "    BL      sub_FF83C1C8 \n"
 362 "    BL      sub_FF8398D8 \n"
 363 "    BL      sub_FF83C33C \n"
 364 "    BL      CreateTask_spytask\n"  // added
 365 "    BL      taskcreatePhySw_my \n"  // --> Patched. Old value = 0xFF834248.
 366 "    LDR     PC, =0xFF81FC28 \n"  // Continue in firmware
 367 );
 368 }
 369 
 370 /*************************************************************/
 371 //** taskcreatePhySw_my @ 0xFF834248 - 0xFF834268, length=9
 372 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 373 asm volatile (
 374 "    STMFD   SP!, {R3-R5,LR} \n"
 375 "    LDR     R4, =0x1C30 \n"
 376 "    LDR     R0, [R4, #4] \n"
 377 "    CMP     R0, #0 \n"
 378 "    BNE     sub_FF83427C \n"
 379 "    MOV     R3, #0 \n"
 380 "    STR     R3, [SP] \n"
 381 "    LDR     R3, =mykbd_task \n"  // --> Patched. Old value = 0xFF834214.
 382 "    MOV     R2, #0x2000 \n"  // --> Patched. Old value = 0x800. stack size for new task_PhySw
 383 "    LDR     PC, =0xFF83426C \n"  // Continue in firmware
 384 );
 385 }
 386 
 387 /*************************************************************/
 388 //** init_file_modules_task @ 0xFF8933BC - 0xFF8933D8, length=8
 389 void __attribute__((naked,noinline)) init_file_modules_task() {
 390 asm volatile (
 391 "    STMFD   SP!, {R4-R6,LR} \n"
 392 "    BL      sub_FF88B35C \n"
 393 "    LDR     R5, =0x5006 \n"
 394 "    MOVS    R4, R0 \n"
 395 "    MOVNE   R1, #0 \n"
 396 "    MOVNE   R0, R5 \n"
 397 "    BLNE    _PostLogicalEventToUI \n"
 398 "    BL      sub_FF88B388 \n"
 399 "    BL      core_spytask_can_start\n"  // CHDK: Set "it's-safe-to-start" flag for spytask
 400 "    LDR     PC, =0xFF8933DC \n"  // Continue in firmware
 401 );
 402 }

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