Startup. s

Source: Internet
Author: User

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:

  1. Startuptext
  2. Leaf_entry startup
  3. Set the CPSR register of arm to set arm as the management mode and shield all interrupts.
  4. MoV r0, # (svc32mode: Or: noints)
  5. MSR cpsr_c, R0
  6. ; Set CP15 coprocessor, disable MMU and Cache
  7. LDR r0, = cp15controlinit
  8. Wrmmu_state R0
  9. LDR r0, = cp15auxcontrolinit
  10. Wrmmu_aux_state R0
  11. ; Refresh TLB table and Cache
  12. MoV r0, #0x0
  13. Wrmmu_flushtb R0
  14. Wrcache_flushidc R0
  15. ; Release write buffer
  16. MoV r0, #0
  17. MCR P15, 0, R0, C7, C10, 4
  18. Cpwait
  19. Create a temporary stack using the header 32kb In the SRAM
  20. LDR sp, = (cpu_sram0 + sz_32k-4)
  21. BL disableints; block external interruptions
  22. BL inituart; initialize the serial port
  23. BL initclocks; initialize the system clock
  24. BL initstaticmem; initialize the flash chip selection Controller
  25. BL initsdram; initialize the SDRAM Controller
  26. BL sizesdram; return the size of SDRAM
  27. If eboot
  28. ; Relocate the code in flash to ram
  29. BL everythingrelocate
  30. After successful relocation, jump to the new realstartup address to run; otherwise, run
  31. CMP r0, #-1
  32. Movne PC, R0
  33. Endif
  34. Realstartup
  35. If eboot
  36. BL ebootmain; jump to the ebootmain function, which is the C language code of eboot.
  37. Else
  38. ADR r0, oemaddresstable; R0 = physical address of oemmemorymap
  39. BL kernelstart; jump to the kernelstart function and input the Physical Virtual Address ing table.
  40. Endif
  41. Here is an endless loop, and the code should never be executed here
  42. Spin B spin
  43. 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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.