The storage interface timing optimization is very important, for it may affect the performance of the whole system. Practically, storage access is alway the bottleneck that restricts the running speed of the system, therefore we should set the storage access timing as fast as possible while considering the stability of system.
     Storage address distribution:
     One typical way is to start ROM address re-mapping


Initializing stack
     In the ARM architecture there are 7 execution mode, and the stack pointer register (SP) for each mode is independent to each other. Therefore, a stack address must be difined for the SP in each of the modes that would be used in the program. However, DO NOT set the stack in the User mode, because once you have gotten into the User mode, you would not be able to operate the CPSR or switch to other modes, and therefore the execution of the program would be affected.
    The following is a block of codes that used for stack initialization, in which the SP pointers under 3 modes are difined:

MRS  R0,CPSR 
BIC  R0,R0,#MODEMASK //For safty reasons, mask all other bits except the mode bit
ORR  R1,R0,#IRQMODE 
MSR  CPSR_cxfs,R1 
LDR  SP,=UndefStack 

ORR  R1,R0,#FIQMODE 
MSR  CPSR_cxsf,R1 
LDR  SP,=FIQStack 

ORR  R1,R0,#SVCMODE 
MSR  CPSR_cxsf,R1 
LDR  SP,=SVCStack 

Initializing ports and devices with special requirements


     Initializing application execution environment
     Usually, the image is stored in the ROM/Flash memory after it is downloaded, the RO part of the image can be either executed in the ROM/Flash memory or transferred to the RAM and then executed, whiles the RW part and ZI part must be transferred to the writable RAM. The so-called “application execution environment initialization”, is to realize the data tranmission from ROM to RAM and contents ereasing.
     See the example below:

LDR  r0,=|Image$$RO$$Limit| //get the starting address of RW data source

LDR  r1,=|Image$$RW$$Base| //starting address of the RW section in the execution area in RAM