打印
[ARM入门]

关于cortexM0堆栈分配

[复制链接]
1209|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lilyzhong|  楼主 | 2014-9-10 15:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大家好
最近要用keil调试cortexM0的一个程序
之前代码比较小也比较简单都没什么问题
现在这个程序因为要用到很多很大的中间变量,debug的时候到了大数那里就跑不了了
堆栈分配以前也没分过,他的启动代码和网上别人讲的不一样,贴一下代码,大家帮忙看看吧
boot.c中
// Set up initial stack and heap
__value_in_regs struct __initial_stackheap
__user_initial_stackheap(unsigned R0, unsigned SP, unsigned R2, unsigned SL)
{       
  struct __initial_stackheap s;
       
  s.heap_base   = R0;         /* low-address end of initial heap */
  s.stack_base  = SP;         /* high-address end of initial stack */
  s.heap_limit  = s.stack_base; /* high-address end of initial heap */
  s.stack_limit = s.heap_base; /* low-address end of initial stack */
  return s;
}


还有rt_misc.c中相关代码
/*
This must return a pointer to __USER_LIBSPACE_SIZE bytes of zero-initialised space, used to store vital static data such as
errno, the heap state, and the FP status word.*/
#define __USER_LIBSPACE_SIZE 96
extern void *__user_libspace(void);

/*
* 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 */
};
extern __value_in_regs struct __initial_stackheap
__user_initial_stackheap(unsigned /*R0*/, unsigned /*SP*/,
                         unsigned /*R2*/, unsigned /*SL*/);

/*
* This can be defined to give bounds on the address space the heap
* will ever use.
*/
struct __heap_extent {
    unsigned base, range;
};
extern __value_in_regs struct __heap_extent
__user_heap_extent(unsigned /*ignore*/, unsigned /*ignore*/);

/*
* This can be defined to specify how much spare stack is needed
* below SL in addition to the 256 bytes required by ATPCS:
* `always' gives the number of bytes of extra stack required at
* all instants (so that an interrupt handler has space to run in,
* for example), while `cleanup' gives the number of bytes of extra
* stack required to be available after a stack overflow has
* occurred, so that the stack overflow routine (e.g. SIGSTAK
* handler) has room to tidy up.
*/
struct __stack_slop {
    unsigned always, cleanup;
};
extern __value_in_regs struct __stack_slop
__user_stack_slop(unsigned /*ignore*/, unsigned /*ignore*/);

/*
* This can be defined to return extra blocks of memory, separate
* from the initial one, to be used by the heap. It should place a
* pointer to a block of at least the requested size in `*base',
* and return the size of the block. It should return 0 if no such
* block can be returned, in which case the value stored at `*base'
* is never used.
*/
extern unsigned __user_heap_extend(int /*ignore*/,
                                   void ** /*base*/,
                                   unsigned /*requestedsize*/);
这个应该是比较原始的代码
我RAM只是一个模型,分配的起始地址是0x20000000
请问下这里堆栈应该怎么分呢
谢谢



相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

6

帖子

0

粉丝