Embedded Development Learning (9) < write the setup stack for the startup code and call C language >

Source: Internet
Author: User

C language runtime needs and the meaning of the stack:

The C language runtime (runtime) requires certain conditions that are provided by the Assembly. The C language runtime is primarily a need for stacks
C language and the relationship between the stack: C language Local variables are implemented by the stack. If we do not pre-set the C part of the Assembly to a reasonable and reasonable stack address, then the C code defined in the local variables will be lost, the entire program is dead.
We usually write a microcontroller program (such as 51 microcontroller) or write the application does not go to set the stack, but the C program can still run. The reason is: in the microcontroller by the hardware initialization provides a default available stack, in the application we write the C program is not all, the compiler (GCC) at the time of the link will help us to automatically add a header, this is a section of the Code to guide our C program can execute a piece of the implementation of the Assembly, This code helps to set up the stack and other runtime requirements for our C program.

CPU mode and stacks in various modes:

In arm 37 registers, each mode has its own independent SP Register (R13), why so design?
If all modes use the same SP, it means that the entire program (the operating system kernel program, the user's own application) is a stack. If your application fails (such as a stack overflow), it will corrupt the stack of the operating system and the entire operating system will crash. Such an operating system design is very fragile and unreasonable.
The solution is to use different stacks in various modes. My operating system kernel uses its own stack, each application also uses its own stand-alone stack, each of which is different, and one corruption does not implicate others.
We now want to set up the stack, can not be lazy and there is no need to set all the stack, we first have to find their own mode, and then set their own mode of the stack to a reasonable and reasonable position, you can.
Note: The system enters the SVC mode by default after reset
How do we access the SP in SVC mode? Very simple, first set the mode to SVC, and then directly operate the SP. But since we reset it is already SVC mode, so directly set the SP can.

S5PV210 's Memory Map such as:

  

Embedded Development Learning (9) < write the setup stack for the startup code and call C language >

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.