[ARM入门] 关于cortexM0堆栈分配

[复制链接]
1428|0
 楼主| lilyzhong 发表于 2014-9-10 15:45 | 显示全部楼层 |阅读模式
大家好
最近要用keil调试cortexM0的一个程序
之前代码比较小也比较简单都没什么问题
现在这个程序因为要用到很多很大的中间变量,debug的时候到了大数那里就跑不了了
堆栈分配以前也没分过,他的启动代码和网上别人讲的不一样,贴一下代码,大家帮忙看看吧
boot.c中
  1. // Set up initial stack and heap
  2. __value_in_regs struct __initial_stackheap
  3. __user_initial_stackheap(unsigned R0, unsigned SP, unsigned R2, unsigned SL)
  4. {       
  5.   struct __initial_stackheap s;
  6.        
  7.   s.heap_base   = R0;         /* low-address end of initial heap */
  8.   s.stack_base  = SP;         /* high-address end of initial stack */
  9.   s.heap_limit  = s.stack_base; /* high-address end of initial heap */
  10.   s.stack_limit = s.heap_base; /* low-address end of initial stack */
  11.   return s;
  12. }


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

  6. /*
  7. * This can be defined to override the standard memory models' way
  8. * of determining where to put the initial stack and heap.
  9. *
  10. * The input parameters R0 and R2 contain nothing useful. The input
  11. * parameters SP and SL are the values that were in SP and SL when
  12. * the program began execution (so you can return them if you want
  13. * to keep that stack).
  14. *
  15. * The two `limit' fields in the return structure are ignored if
  16. * you are using the one-region memory model: the memory region is
  17. * taken to be all the space between heap_base and stack_base.
  18. */
  19. struct __initial_stackheap {
  20.     unsigned heap_base;                /* low-address end of initial heap */
  21.     unsigned stack_base;               /* high-address end of initial stack */
  22.     unsigned heap_limit;               /* high-address end of initial heap */
  23.     unsigned stack_limit;              /* low-address end of initial stack */
  24. };
  25. extern __value_in_regs struct __initial_stackheap
  26. __user_initial_stackheap(unsigned /*R0*/, unsigned /*SP*/,
  27.                          unsigned /*R2*/, unsigned /*SL*/);

  28. /*
  29. * This can be defined to give bounds on the address space the heap
  30. * will ever use.
  31. */
  32. struct __heap_extent {
  33.     unsigned base, range;
  34. };
  35. extern __value_in_regs struct __heap_extent
  36. __user_heap_extent(unsigned /*ignore*/, unsigned /*ignore*/);

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

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



您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

6

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部