_ User_initial_stackheap settings

Source: Internet
Author: User
In ARM embedded programming, you need to set the size of the stack space. There is a function to set the size of the stack space. This function is: __ user_initial_stackheap. Next I will copy the content of this function:
/** This can be defined to override the standard memory models 'way * of determining where to put the initial stack and heap. ** the input parameters R0 and R2 contain nothing useful. the input * parameters SP and SL are the values that were in SP and SL when * The program began execution (so you can return them if you want * to keep that stack ). ** the two 'limit' fields in the return structure are ignored if * you are using the one-Region Memory Model: the memory region is * taken to be all the space between heap_base and stack_base. */struct _ initial_stackheap {unsigned heap_base;/* low-address end of initial heap */unsigned stack_base;/* High-address end of initial stack */unsigned heap_limit; /* High-address end of initial heap */unsigned stack_limit;/* low-address end of initial stack */}; // * handle // * Function Name: _ user_initial_stackheap // * object: returns the locations of the initial stack and heap. // * input parameters: // * output parameters: the values returned in R0 to R3 depend on whether you // * are using the one or two region model: // * one region (r0, R1) is the single stack and heap region. r1 is // * greater than r0.r2 and R3 are ignored. // * two regions (r0, R2) is the initial heap and (R3, R1) is the initial // * stack. r2 is greater than or equal to r0.r3 is less than R1. // * functions called: NONE // * functions _ value_in_regs struct _ initial_stackheap _ user_initial_stackheap (unsigned r0, unsigned sp, unsigned R2, unsigned SL) {struct _ initial_stackheap config; config. stack_base = sp; config. stack_limit = SP-STACK_SIZE; config. heap_base = (unsigned) (user_heap_address); config. heap_limit = (unsigned) (User _ heap_address) + user_sram_size; return config ;}

The usage of this function can be clearly seen from the above annotations.

The stack area is configured in two modes: single-zone and dual-zone.

In a single zone, the heap and stack share a space area. Heap increases from high address to low address. Stack increases from low address to high address. Two hits,ProgramIt crashes. The last two parametersStack_limitAndHeap_limitNo configuration is required.

In dual-zone mode, the heap and stack have independent space areas.SPYesRamPointer to the highest position. The same is true for growth.

Pay attention to the stack growth direction When configuring these four parameters.

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.