__user_initial_stackheap的设定

 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_limitheap_limit不用配置。

双区的时候,堆和栈是有各自独立的空间区域。SPRAM的最高位置的指针。增长方向也是一样的。

在配置这四个参数时要注意堆栈的增长方向。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值