stack.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2008-12-11 XuXinming first version
  13. * 2013-05-24 Grissiom port to RM48x50
  14. */
  15. #include <rtthread.h>
  16. #include "RM48x50.h"
  17. /**
  18. * @addtogroup RM48x50
  19. */
  20. /*@{*/
  21. /**
  22. * This function will initialize thread stack
  23. *
  24. * @param tentry the entry of thread
  25. * @param parameter the parameter of entry
  26. * @param stack_addr the beginning stack address
  27. * @param texit the function will be called when thread exit
  28. *
  29. * @return stack address
  30. */
  31. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  32. rt_uint8_t *stack_addr, void *texit)
  33. {
  34. unsigned long *stk;
  35. stk = (unsigned long*)stack_addr;
  36. *( stk) = (unsigned long) tentry; /* entry point */
  37. *(--stk) = (unsigned long) texit; /* lr */
  38. *(--stk) = 0; /* r12 */
  39. *(--stk) = 0; /* r11 */
  40. *(--stk) = 0; /* r10 */
  41. *(--stk) = 0; /* r9 */
  42. *(--stk) = 0; /* r8 */
  43. *(--stk) = 0; /* r7 */
  44. *(--stk) = 0; /* r6 */
  45. *(--stk) = 0; /* r5 */
  46. *(--stk) = 0; /* r4 */
  47. *(--stk) = 0; /* r3 */
  48. *(--stk) = 0; /* r2 */
  49. *(--stk) = 0; /* r1 */
  50. *(--stk) = (unsigned long)parameter; /* r0 : argument */
  51. /* cpsr */
  52. if ((rt_uint32_t)tentry & 0x01)
  53. *(--stk) = SVCMODE | 0x20; /* thumb mode */
  54. else
  55. *(--stk) = SVCMODE; /* arm mode */
  56. #ifdef __TI_VFP_SUPPORT__
  57. #ifndef RT_VFP_LAZY_STACKING
  58. {
  59. #define VFP_DATA_NR 32
  60. int i;
  61. for (i = 0; i < VFP_DATA_NR; i++)
  62. {
  63. *(--stk) = 0;
  64. }
  65. /* FPSCR TODO: do we need to set the values other than 0? */
  66. *(--stk) = 0;
  67. /* FPEXC. Enable the FVP if no lazy stacking. */
  68. *(--stk) = 0x40000000;
  69. }
  70. #else
  71. /* FPEXC. Disable the FVP by default. */
  72. *(--stk) = 0x00000000;
  73. #endif
  74. #endif
  75. /* return task's current stack address */
  76. return (rt_uint8_t *)stk;
  77. }
  78. /*@}*/