__user_initial_stackheap的設定

來源:互聯網
上載者:User
 ARM嵌入式編程中需要設定堆棧的空間大小,設定堆棧空間大小是有一個函數來實現的,這個函數就是:__user_initial_stackheap。下面我將這個函數的內容拷貝出來:
/* * 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 */};//*----------------------------------------------------------------------------//* 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//*----------------------------------------------------------------------------__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; }

從上面的注釋,可以清楚的看出來這個函數的用法。

在配置堆棧地區的時候分為兩個模式:單區和雙區。

單區的時候,堆和棧共用一塊空間地區。堆從高地址往低地址增長。棧從低地址向高地址增長。兩個撞上了,程式就崩潰。這時後兩個參數stack_limit和heap_limit不用配置。

雙區的時候,堆和棧是有各自獨立的空間地區。SP是RAM的最高位置的指標。增長方向也是一樣的。

在配置這四個參數時要注意堆棧的增長方向。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.