Author: arm-WinCE
The startup. s file contains a startup entry function, which is the initial entry of eboot. This is the first function to be executed when the system is powered on or cold-started. This function is written in an assembly language to complete initial initialization Based on the hardware platform, that is, CPU initialization. If necessary, you can also initialize peripheral devices here. When the function is executed to the end, it will jump to the C language entry, usually the main function, or the ebootmain function.
One thing to mention here is that there are two startup. s files in BSP, one is the startup. s file of eboot for eboot itself, and the other is the startup. s file of oal for wince kernel. In many cases, the tasks completed by the two startup. s are very similar, so they are generally merged into a startup. s to complete the corresponding functions. For example, after you complete the initialization operation in startup. s of eboot, you only need to include startup. s under eboot in startup. s of OAL. Of course, the two startups. S may not be exactly the same, so whether there are actually two startups. the S file still shares a startup. s file, you may need. in S, it is distinguished by Conditional compilation or the method for determining a variable.
In startup. s, what should I do:
1. When the system is powered on or reset, set the CPU to the correct mode. Generally, the CPU itself has several modes. For example, for arm, it is usually setManagement Mode.
2. Disable all CPU interruptions.
3. Disable memory management units MMU and TLB.
4. Disable the write buffer and cache.
5. initialize the memory controller.
6. Set the PLL of the CPU and set the clock.
7. Create a stack.
8. Set and enable MMU and cache.
9. Copy the eboot file from flash to ram as needed.
10. Jump to the C code, usually the main function or ebootmain function.
The following uses arm as an example to describe a startup. s template:
- Startuptext
- Leaf_entry startup
- Set the CPSR register of arm to set arm as the management mode and shield all interrupts.
- MoV r0, # (svc32mode: Or: noints)
- MSR cpsr_c, R0
- ; Set CP15 coprocessor, disable MMU and Cache
- LDR r0, = cp15controlinit
- Wrmmu_state R0
- LDR r0, = cp15auxcontrolinit
- Wrmmu_aux_state R0
- ; Refresh TLB table and Cache
- MoV r0, #0x0
- Wrmmu_flushtb R0
- Wrcache_flushidc R0
- ; Release write buffer
- MoV r0, #0
- MCR P15, 0, R0, C7, C10, 4
- Cpwait
- Create a temporary stack using the header 32kb In the SRAM
- LDR sp, = (cpu_sram0 + sz_32k-4)
- BL disableints; block external interruptions
- BL inituart; initialize the serial port
- BL initclocks; initialize the system clock
- BL initstaticmem; initialize the flash chip selection Controller
- BL initsdram; initialize the SDRAM Controller
- BL sizesdram; return the size of SDRAM
- If eboot
- ; Relocate the code in flash to ram
- BL everythingrelocate
- After successful relocation, jump to the new realstartup address to run; otherwise, run
- CMP r0, #-1
- Movne PC, R0
- Endif
- Realstartup
- If eboot
- BL ebootmain; jump to the ebootmain function, which is the C language code of eboot.
- Else
- ADR r0, oemaddresstable; R0 = physical address of oemmemorymap
- BL kernelstart; jump to the kernelstart function and input the Physical Virtual Address ing table.
- Endif
- Here is an endless loop, and the code should never be executed here
- Spin B spin
- Entry_end
Entire startup. this is the process of S. Generally, developing this Code requires a better understanding of the processor and assembly language. In fact, it is not very complicated, that is, the most basic initialization, and the function is usually several hundred lines. Debugging may be a little difficult. At the very beginning, debugging is generally done by lighting (LED), that is, writing a small assembler function, by pulling down gpio height, the LED lights are lit up and off. Then, call the function at different locations in startup. s to determine whether the function is executed in the corresponding place.