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

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

DEFINITIONS

This source file includes following definitions.
  1. taskHook
  2. boot
  3. sub_FF810380_my
  4. sub_FF8111D8_my
  5. sub_FF814278_my
  6. sub_FF81A698_my
  7. taskcreate_Startup_my
  8. task_Startup_my
  9. taskcreatePhySw_my
  10. CreateTask_spytask
  11. init_file_modules_task

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "dryos31.h"
   5 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
   6 
   7 const char * const new_sa = &_end;
   8 
   9 void CreateTask_PhySw();
  10 void CreateTask_spytask();
  11 
  12 extern void task_CaptSeq();
  13 extern void task_InitFileModules();
  14 extern void task_MovieRecord();
  15 extern void task_ExpDrv();
  16 extern void task_PhySw();
  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     if(tcb->entry == (void*)task_PhySw)            tcb->entry = (void*)mykbd_task;
  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 //#define LED_GREEN             0xC0220120
  32 
  33 //** boot  @ 0xFF81000C 
  34 
  35 void __attribute__((naked,noinline)) boot() {
  36 asm volatile (
  37       "LDR     R1, =0xC0410000 \n"
  38       "MOV     R0, #0 \n"
  39       "STR     R0, [R1] \n"
  40       "MOV     R1, #0x78 \n"
  41       "MCR     p15, 0, R1, c1, c0 \n"
  42       "MOV     R1, #0 \n"
  43       "MCR     p15, 0, R1, c7, c10, 4 \n"
  44       "MCR     p15, 0, R1, c7, c5 \n"
  45       "MCR     p15, 0, R1, c7, c6 \n"
  46       "MOV     R0, #0x3D \n"
  47       "MCR     p15, 0, R0, c6, c0 \n"
  48       "MOV     R0, #0xC000002F \n"
  49       "MCR     p15, 0, R0, c6, c1 \n"
  50       "MOV     R0, #0x33 \n"
  51       "MCR     p15, 0, R0, c6, c2 \n"
  52       "MOV     R0, #0x40000033 \n"
  53       "MCR     p15, 0, R0, c6, c3 \n"
  54       "MOV     R0, #0x80000017 \n"
  55       "MCR     p15, 0, R0, c6, c4 \n"
  56       "LDR     R0, =0xFF80002D \n"
  57       "MCR     p15, 0, R0, c6, c5 \n"
  58       "MOV     R0, #0x34 \n"
  59       "MCR     p15, 0, R0, c2, c0 \n"
  60       "MOV     R0, #0x34 \n"
  61       "MCR     p15, 0, R0, c2, c0, 1 \n"
  62       "MOV     R0, #0x34 \n"
  63       "MCR     p15, 0, R0, c3, c0 \n"
  64       "LDR     R0, =0x3333330 \n"
  65       "MCR     p15, 0, R0, c5, c0, 2 \n"
  66       "LDR     R0, =0x3333330 \n"
  67       "MCR     p15, 0, R0, c5, c0, 3 \n"
  68       "MRC     p15, 0, R0, c1, c0 \n"
  69       "ORR     R0, R0, #0x1000 \n"
  70       "ORR     R0, R0, #4 \n"
  71       "ORR     R0, R0, #1 \n"
  72       "MCR     p15, 0, R0, c1, c0 \n"
  73       "MOV     R1, #0x80000006 \n"
  74       "MCR     p15, 0, R1, c9, c1 \n"
  75       "MOV     R1, #6 \n"
  76       "MCR     p15, 0, R1, c9, c1, 1 \n"
  77       "MRC     p15, 0, R1, c1, c0 \n"
  78       "ORR     R1, R1, #0x50000 \n"
  79       "MCR     p15, 0, R1, c1, c0 \n"
  80       "LDR     R2, =0xC0200000 \n"
  81       "MOV     R1, #1 \n"
  82       "STR     R1, [R2, #0x10C] \n"
  83       "MOV     R1, #0xFF \n"
  84       "STR     R1, [R2, #0xC] \n"
  85       "STR     R1, [R2, #0x1C] \n"
  86       "STR     R1, [R2, #0x2C] \n"
  87       "STR     R1, [R2, #0x3C] \n"
  88       "STR     R1, [R2, #0x4C] \n"
  89       "STR     R1, [R2, #0x5C] \n"
  90       "STR     R1, [R2, #0x6C] \n"
  91       "STR     R1, [R2, #0x7C] \n"
  92       "STR     R1, [R2, #0x8C] \n"
  93       "STR     R1, [R2, #0x9C] \n"
  94       "STR     R1, [R2, #0xAC] \n"
  95       "STR     R1, [R2, #0xBC] \n"
  96       "STR     R1, [R2, #0xCC] \n"
  97       "STR     R1, [R2, #0xDC] \n"
  98       "STR     R1, [R2, #0xEC] \n"
  99       "STR     R1, [R2, #0xFC] \n"
 100       "LDR     R1, =0xC0400008 \n"
 101       "LDR     R2, =0x430005 \n"
 102       "STR     R2, [R1] \n"
 103       "MOV     R1, #1 \n"
 104       "LDR     R2, =0xC0243100 \n"
 105       "STR     R2, [R1] \n"
 106       "LDR     R2, =0xC0242010 \n"
 107       "LDR     R1, [R2] \n"
 108       "ORR     R1, R1, #1 \n"
 109       "STR     R1, [R2] \n"
 110       "LDR     R0, =0xFFC04D4C \n"
 111       "LDR     R1, =0x3F1000 \n"
 112       "LDR     R3, =0x4005D4 \n"
 113 "loc_FF81013C:\n"
 114       "CMP     R1, R3 \n"
 115       "LDRCC   R2, [R0], #4 \n"
 116       "STRCC   R2, [R1], #4 \n"
 117       "BCC     loc_FF81013C \n"
 118       "LDR     R0, =0xFFBF93D0 \n"
 119       "LDR     R1, =0x1900 \n"
 120       "LDR     R3, =0xD27C \n"
 121 "loc_FF810158:\n"
 122       "CMP     R1, R3 \n"
 123       "LDRCC   R2, [R0], #4 \n"
 124       "STRCC   R2, [R1], #4 \n"
 125       "BCC     loc_FF810158 \n"
 126       "LDR     R1, =0x157C84 \n" //MEMISOSTART
 127       "MOV     R2, #0 \n"
 128 "loc_FF810170:\n"
 129       "CMP     R3, R1 \n"
 130       "STRCC   R2, [R3], #4 \n"
 131       "BCC     loc_FF810170 \n"
 132 //      "B       sub_FF810380 \n" //original
 133       "B       sub_FF810380_my \n" //patched
 134         );
 135 }
 136 
 137 //** sub_FF810380_my  @ 0xFF810380 
 138 
 139 void __attribute__((naked,noinline)) sub_FF810380_my() {
 140 
 141    //http://chdk.setepontos.com/index.php/topic,4194.0.html
 142    *(int*)0x1934=(int)taskHook;
 143    *(int*)0x1938=(int)taskHook;
 144 
 145     // Power Button detection (short press = playback mode, long press = record mode) 
 146         // C0220048  a4000.100c ??
 147     // C02200F8  a4000.100c sub_ff81a6ac : C0220000 (@ff81a6b4) + 0xF8 (@ff81a6fc)
 148     // 0x24B0    a4000.100c loc_ff856420
 149     if ((*(int*) 0xC02200F8) & 1)                 // look at power-on switch
 150             *(int*)(0x24B0+4) = 0x200000;         // start in play mode
 151     else
 152             *(int*)(0x24B0+4) = 0x100000;         // start in rec mode    
 153     
 154 asm volatile (
 155       "LDR     R0, =0xFF8103F8 \n"
 156       "MOV     R1, #0 \n"
 157       "LDR     R3, =0xFF810430 \n"
 158 "loc_FF81038C:\n"
 159       "CMP     R0, R3 \n"
 160       "LDRCC   R2, [R0], #4 \n"
 161       "STRCC   R2, [R1], #4 \n"
 162       "BCC     loc_FF81038C \n"
 163       "LDR     R0, =0xFF810430 \n"
 164       "MOV     R1, #0x4B0 \n"
 165       "LDR     R3, =0xFF810644 \n"
 166 "loc_FF8103A8:\n"
 167       "CMP     R0, R3 \n"
 168       "LDRCC   R2, [R0], #4 \n"
 169       "STRCC   R2, [R1], #4 \n"
 170       "BCC     loc_FF8103A8 \n"
 171       "MOV     R0, #0xD2 \n"
 172       "MSR     CPSR_cxsf, R0 \n"
 173       "MOV     SP, #0x1000 \n"
 174       "MOV     R0, #0xD3 \n"
 175       "MSR     CPSR_cxsf, R0 \n"
 176       "MOV     SP, #0x1000 \n"
 177       "LDR     R0, =0x6C4 \n"
 178       "LDR     R2, =0xEEEEEEEE \n"
 179       "MOV     R3, #0x1000 \n"
 180 "loc_FF8103DC:\n"
 181       "CMP     R0, R3 \n"
 182       "STRCC   R2, [R0], #4 \n"
 183       "BCC     loc_FF8103DC \n"
 184 //      "BL      sub_FF8111D8 \n" //original
 185       "BL      sub_FF8111D8_my \n" //patched
 186         );
 187 }
 188 
 189 //** sub_FF8111D8_my  @ 0xFF8111D8 
 190 
 191 void __attribute__((naked,noinline)) sub_FF8111D8_my() {
 192 asm volatile (
 193       "STR     LR, [SP, #-4]! \n"
 194       "SUB     SP, SP, #0x74 \n"
 195       "MOV     R1, #0x74 \n"
 196       "MOV     R0, SP \n"
 197       "BL      sub_003FC448 \n" //RAM
 198       "MOV     R0, #0x57000 \n"
 199       "STR     R0, [SP, #4] \n"
 200 #if defined(CHDK_NOT_IN_CANON_HEAP)
 201       "LDR     R0, =0x157C84 \n" // MEMISOSTART: Use original heap offset since CHDK is loaded in high memory 
 202 #else
 203       "LDR     R0, =new_sa \n"      //otherwise use patched value
 204       "LDR     R0, [R0] \n"
 205 #endif
 206       "LDR     R2, =0x2ED440 \n"
 207       "STR     R0, [SP, #8] \n"
 208       "SUB     R0, R2, R0 \n"
 209       "STR     R0, [SP, #0xC] \n"
 210       "MOV     R0, #0x22 \n"
 211       "STR     R0, [SP, #0x18] \n"
 212       "MOV     R0, #0x7C \n"
 213       "STR     R0, [SP, #0x1C] \n"
 214       "LDR     R1, =0x2F5C00 \n"
 215       "LDR     R0, =0x1CD \n"
 216       "STR     R1, [SP] \n"
 217       "STR     R0, [SP, #0x20] \n"
 218       "MOV     R0, #0x96 \n"
 219       "STR     R2, [SP, #0x10] \n"
 220       "STR     R1, [SP, #0x14] \n"
 221       "STR     R0, [SP, #0x24] \n"
 222       "STR     R0, [SP, #0x28] \n"
 223       "MOV     R0, #0x64 \n"
 224       "STR     R0, [SP, #0x2C] \n"
 225       "MOV     R0, #0 \n"
 226       "STR     R0, [SP, #0x30] \n"
 227       "STR     R0, [SP, #0x34] \n"
 228       "MOV     R0, #0x10 \n"
 229       "STR     R0, [SP, #0x5C] \n"
 230       "MOV     R0, #0x800 \n"
 231       "STR     R0, [SP, #0x60] \n"
 232       "MOV     R0, #0xA0 \n"
 233       "STR     R0, [SP, #0x64] \n"
 234       "MOV     R0, #0x280 \n"
 235       "STR     R0, [SP, #0x68] \n"
 236 //      "LDR     R1, =0xFF814278 \n" //original
 237       "LDR     R1, =sub_FF814278_my \n" //patched
 238       "MOV     R2, #0 \n"
 239       "MOV     R0, SP \n"
 240       "BL      sub_003F2778 \n"
 241       "ADD     SP, SP, #0x74 \n"
 242       "LDR     PC, [SP], #4 \n"
 243         );
 244 }
 245 
 246 //** sub_FF814278_my  @ 0xFF814278 
 247 
 248 void __attribute__((naked,noinline)) sub_FF814278_my() {
 249 asm volatile (
 250       "STMFD   SP!, {R4,LR} \n"
 251       "BL      sub_FF810B50 \n"
 252       "BL      sub_FF815164 \n"
 253       "CMP     R0, #0 \n"
 254       "LDRLT   R0, =0xFF81438C \n" // "dmSetup"
 255       "BLLT    _err_init_task \n"
 256       "BL      sub_FF813EB0 \n"
 257       "CMP     R0, #0 \n"
 258       "LDRLT   R0, =0xFF814394 \n" // "termDriverInit"
 259       "BLLT    _err_init_task \n"
 260       "LDR     R0, =0xFF8143A4 \n" // "/_term"
 261       "BL      sub_FF813F98 \n"
 262       "CMP     R0, #0 \n"
 263       "LDRLT   R0, =0xFF8143AC \n" // "termDeviceCreate"
 264       "BLLT    _err_init_task \n"
 265       "LDR     R0, =0xFF8143A4 \n" //  "/_term"
 266       "BL      sub_FF8129B8 \n"
 267       "CMP     R0, #0 \n"
 268       "LDRLT   R0, =0xFF8143C0 \n" // "stdioSetup"
 269       "BLLT    _err_init_task \n"
 270       "BL      sub_FF814B00 \n"
 271       "CMP     R0, #0 \n"
 272       "LDRLT   R0, =0xFF8143CC \n" // "stdlibSetup"
 273       "BLLT    _err_init_task \n"
 274       "BL      sub_FF8116B8 \n"
 275       "CMP     R0, #0 \n"
 276       "LDRLT   R0, =0xFF8143D8 \n" // "armlib_setup"
 277       "BLLT    _err_init_task \n"
 278       "LDMFD   SP!, {R4,LR} \n"
 279 //      "B       sub_FF81A698 \n" //original
 280       "B       sub_FF81A698_my \n" //patched
 281         );
 282 }
 283 
 284 //** sub_FF81A698_my  @ 0xFF81A698 
 285 
 286 void __attribute__((naked,noinline)) sub_FF81A698_my() {
 287 asm volatile (
 288       "STMFD   SP!, {R4,LR} \n"
 289       "BL      sub_FF82EAD8 \n"
 290 //      "BL      loc_FF81A6AC \n" // original taskcreate_Startup
 291       "BL      taskcreate_Startup_my \n" //patched taskcreate_Startup
 292       "MOV     R0, #0 \n"
 293       "LDMFD   SP!, {R4,PC} \n"
 294         );
 295 }
 296 
 297 //** taskcreate_Startup_my  @ 0xFF81A6AC 
 298 
 299 void __attribute__((naked,noinline)) taskcreate_Startup_my() {
 300 asm volatile (
 301       "STMFD   SP!, {R3-R7,LR} \n"
 302       "BL      sub_FF835B84 \n"
 303       "LDR     R6, =0xC0220000 \n"
 304       "MOVS    R4, R0 \n"
 305       "MOV     R5, #1 \n"
 306       "BNE     loc_FF81A6FC \n"
 307       "BL      sub_FF830534 \n"
 308       "CMP     R0, #0 \n"
 309       "BEQ     loc_FF81A6FC \n"
 310       "LDR     R0, [R6, #0xFC] \n"
 311       "BIC     R1, R5, R0 \n"
 312       "LDR     R0, [R6, #0xF8] \n"
 313       "BIC     R0, R5, R0 \n"
 314       "ORRS    R2, R0, R1 \n"
 315       "BNE     loc_FF81A70C \n"
 316       "BL      sub_FF82E1A4 \n"
 317       "MOV     R0, #0x44 \n"
 318       "STR     R0, [R6, #0x12C] \n"
 319       "BL      sub_FF82E2B4 \n"
 320 "loc_FF81A6F8:\n"
 321       "B       loc_FF81A6F8 \n"
 322 "loc_FF81A6FC:\n"
 323       "LDR     R0, [R6, #0xF8] \n"
 324       "LDR     R1, [R6, #0xFC] \n"
 325       "BIC     R0, R5, R0 \n"
 326       "BIC     R1, R5, R1 \n"
 327 "loc_FF81A70C:\n"
 328       "MOV     R3, #0 \n"
 329       "MOV     R2, R4 \n"
 330 //      "BL      sub_FF82EAE0 \n" // StartUp mode detection. We must remove this for power-on mode handling to work
 331       "BL      sub_FF82EADC \n"
 332       "BL      sub_003F77E0 \n"
 333       "LDR     R1, =0x34E000 \n"
 334       "MOV     R0, #0 \n"
 335       "BL      sub_FF8341C0 \n"
 336       "BL      sub_003F79F8 \n"
 337       "MOV     R3, #0 \n"
 338       "STR     R3, [SP] \n"
 339 //      "LDR     R3, =0xFF81A628 \n" //original
 340       "LDR     R3, =task_Startup_my \n" //patched
 341       "MOV     R2, #0 \n"
 342       "MOV     R1, #0x19 \n"
 343       "LDR     R0, =0xFF81A760 \n"
 344       "BL      _CreateTask \n"
 345       "MOV     R0, #0 \n"
 346       "LDMFD   SP!, {R3-R7,PC} \n"
 347         );
 348 }
 349 
 350 //** task_Startup_my  @ 0xFF81A628
 351 
 352 void __attribute__((naked,noinline)) task_Startup_my() {
 353 asm volatile (
 354       "STMFD   SP!, {R4,LR} \n"
 355       "BL      sub_FF8148B8 \n"
 356       "BL      sub_FF82FC00 \n"
 357       "BL      sub_FF82DE4C \n"
 358       "BL      sub_FF835BCC \n"
 359       "BL      sub_FF835DB8 \n"
 360       "BL      sub_FF82CC48 \n"
 361       "BL      sub_FF82D810 \n"
 362 //      "BL      sub_FF835C60 \n" //disable Diskboot.bin
 363       "BL      sub_FF835F34 \n"
 364       "BL      sub_FF836100 \n"
 365       "BL      sub_FF835EF8 \n"
 366       "BL      sub_FF835DE8 \n"
 367       "BL      sub_FF8340F4 \n"
 368       "BL      sub_FF836108 \n"
 369       "BL     CreateTask_spytask \n"            //added to create the Spytask
 370 //      "BL      sub_FF82E97C \n" //original taskcreate_PhySw()
 371       "BL     taskcreatePhySw_my \n"            // patched taskcreate_PhySw()
 372       "BL      sub_FF83235C \n"
 373       "BL      sub_FF836120 \n"
 374       "BL      sub_FF82B9C8 \n"
 375       "BL      sub_FF82C510 \n"
 376       "BL      sub_FF835940 \n"
 377       "BL      sub_FF82CB38 \n"
 378       "BL      sub_FF82C4AC \n"
 379       "BL      sub_FF835F24 \n"
 380       "BL      sub_FF836C78 \n" //StartFactoryModeController
 381       "BL      sub_FF82C470 \n"
 382       "LDMFD   SP!, {R4,LR} \n"
 383       "B       sub_FF8149D8 \n"
 384         );
 385 }
 386 
 387 
 388 //** taskcreatePhySw_my  @ 0xFF82E97C 
 389 
 390 void __attribute__((naked,noinline)) taskcreatePhySw_my() {
 391 asm volatile (
 392       "STMFD   SP!, {R3-R5,LR} \n"
 393       "LDR     R4, =0x1C18 \n"
 394       "LDR     R0, [R4, #4] \n"
 395       "CMP     R0, #0 \n"
 396       "BNE     loc_FF82E9B0 \n"
 397       "MOV     R3, #0 \n"
 398       "STR     R3, [SP] \n"
 399 //      "LDR     R3, =0xFF82E948 \n" //original
 400       "LDR     R3, =task_PhySw \n" //patched  task_PhySw
 401 //      "MOV     R2, #0x800 \n" // original  
 402       "MOV     R2, #0x2000 \n" // stack size for new task_PhySw so we don't have to do stack switch
 403       "MOV     R1, #0x17 \n"
 404       "LDR     R0, =0xFF82EBD8 \n"
 405       "BL      sub_003F7A50 \n"
 406       "STR     R0, [R4, #4] \n"
 407 "loc_FF82E9B0:\n"
 408       "BL      sub_FF87EE60 \n"
 409       "BL      sub_FF830484 \n"
 410       "CMP     R0, #0 \n"
 411       "BNE     loc_FF82E9CC \n"
 412       "LDR     R1, =0x3127C \n"
 413       "MOV     R0, #0 \n"
 414       "BL      sub_FF87EDD0 \n"
 415 "loc_FF82E9CC:\n"
 416       "LDMFD   SP!, {R3-R5,PC} \n"
 417         );
 418 }
 419 
 420 void CreateTask_spytask() {
 421 
 422         _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);                        
 423 };
 424 
 425 //** init_file_modules_task  @ 0xFF88895C 
 426 
 427 void __attribute__((naked,noinline)) init_file_modules_task() {
 428 asm volatile (
 429       "STMFD   SP!, {R4-R6,LR} \n"
 430       "BL      sub_FF8813CC \n"
 431       "LDR     R5, =0x5006 \n"
 432       "MOVS    R4, R0 \n"
 433       "MOVNE   R1, #0 \n"
 434       "MOVNE   R0, R5 \n"
 435       "BLNE    _PostLogicalEventToUI \n"
 436       "BL      sub_FF8813F8 \n"
 437       "BL          core_spytask_can_start \n" //added CHDK: Set "it's-safe-to-start"-Flag for spytask
 438       "CMP     R4, #0 \n"
 439       "LDMNEFD SP!, {R4-R6,PC} \n"
 440       "MOV     R0, R5 \n"
 441       "LDMFD   SP!, {R4-R6,LR} \n"
 442       "MOV     R1, #0 \n"
 443       "B       _PostLogicalEventToUI \n"
 444         );
 445 }

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