shutdown() - General Discussion and Assistance - CHDK Forum supplierdeeply

shutdown()

  • 4 Replies
  • 2673 Views
*

Offline reyalp

  • ******
  • 14118
shutdown()
« on: 23 / February / 2009, 00:43:19 »
Advertisements
In both loader and various lib.c, shutdown looks something like:
Code: [Select]
void shutdown()
{
    volatile long *p = (void*)0xC02200A0;
       
    asm(
         "MRS     R1, CPSR\n"
         "AND     R0, R1, #0x80\n"
         "ORR     R1, R1, #0x80\n"
         "MSR     CPSR_cf, R1\n"
         :::"r1","r0");
       
    *p = 0x44;

    while(1);
}
It looks like the address is usually (?) an LED, but many cameras have been copy/pasted without updating, and some even use different ones between loader and platform.

If it is an LED, surely it turns off anyway when the cam shuts down ? If it's not, then what is it ?

The rest of it appears intended to disable IRQs (needlessly setting R0 to the old I bit value) and go into a tight loop, presumably triggering the watchdog ?
Don't forget what the H stands for.

*

Offline whoever

  • ****
  • 280
  • IXUS950
Re: shutdown()
« Reply #1 on: 23 / February / 2009, 03:36:36 »
shutdown() is called frpm panic(). Do you see where panic() is called from? I don't. (Am looking at somewhat "outdated" code though;-) Must've been left there for historical reasons, I suppose.

*

Offline reyalp

  • ******
  • 14118
Re: shutdown()
« Reply #2 on: 23 / February / 2009, 04:02:35 »
shutdown is also called from the sanity check platform/main.c, although that is actually pointless with automatic MEMISOSIZE
Don't forget what the H stands for.

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: shutdown()
« Reply #3 on: 23 / February / 2009, 04:12:42 »
Here is its original code (A610 1.00E - first CHDK camera) - called at end of 'Bye' task:
Code: (asm) [Select]
ROM:FFC124EC sub_FFC124EC
ROM:FFC124EC                STR     LR, [SP,#-4]!  
ROM:FFC124F0                 BL      GetSRAndDisableInterrupt
ROM:FFC124F4                 MOV     R3, #0xA0      
ROM:FFC124F8                 ADD     R3, R3, #0xC0000000
ROM:FFC124FC                 ADD     R3, R3, #0x220000
ROM:FFC12500                 MOV     R2, #0x44    
ROM:FFC12504                 STR     R2, [R3]        
ROM:FFC12508
ROM:FFC12508 loc_FFC12508                          
ROM:FFC12508                 B       loc_FFC12508  

Very easy to find it using 0xEAFFFFFE binary search (this is opcode of 'forever loop').
I think that 0xC02200A0 is not LED, but 'power switch' - disconnects batteries from camera, or stops DC-DC converter, or someting like this.

p.s. For a710 this function is more complex:
Code: (asm) [Select]
ROM:FFC12D38 sub_FFC12D38               
ROM:FFC12D38                                     
ROM:FFC12D38                 STR     LR, [SP,#-4]!
ROM:FFC12D3C                 BL      intLock_1     
ROM:FFC12D40                 MOV     R1, #0xC0000000
ROM:FFC12D44                 ADD     R1, R1, #0x410000
ROM:FFC12D48                 LDR     R2, [R1]       
ROM:FFC12D4C                 MOV     R3, #0xA0   
ROM:FFC12D50                 ADD     R3, R3, #0xC0000000
ROM:FFC12D54                 BIC     R2, R2, #1     
ROM:FFC12D58                 ADD     R3, R3, #0x220000
ROM:FFC12D5C                 MOV     R0, #0x44       
ROM:FFC12D60                 STR     R2, [R1]       
ROM:FFC12D64                 STR     R0, [R3]       
ROM:FFC12D68
ROM:FFC12D68 loc_FFC12D68                 
ROM:FFC12D68                 B       loc_FFC12D68   

0xC0410000 is watchdog register.
« Last Edit: 23 / February / 2009, 04:18:10 by ewavr »


*

Offline reyalp

  • ******
  • 14118
Re: shutdown()
« Reply #4 on: 23 / February / 2009, 21:49:25 »
Thanks ewavr, that's clears things up quite a bit :)
Don't forget what the H stands for.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal