stack.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-07-31 zhangjun copy from mini2440
  23. */
  24. #include <rtthread.h>
  25. /**
  26. * This function will initialize thread stack
  27. *
  28. * @param tentry the entry of thread
  29. * @param parameter the parameter of entry
  30. * @param stack_addr the beginning stack address
  31. * @param texit the function will be called when thread exit
  32. *
  33. * @return stack address
  34. */
  35. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  36. rt_uint8_t *stack_addr, void *texit)
  37. {
  38. rt_uint32_t *stk;
  39. //stk = (rt_uint32_t*)stack_addr;
  40. stack_addr += sizeof(rt_uint32_t);
  41. stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
  42. stk = (rt_uint32_t *)stack_addr;
  43. *(--stk) = (rt_uint32_t)tentry; /* entry point */
  44. *(--stk) = (rt_uint32_t)texit; /* ra */
  45. *(--stk) = (rt_uint32_t)parameter; /* a0 */
  46. *(--stk) = 0xffffffff; /* a1 */
  47. *(--stk) = 0xffffffff; /* a2 */
  48. *(--stk) = 0xffffffff; /* a3 */
  49. *(--stk) = 0xffffffff; /* a4 */
  50. *(--stk) = 0xffffffff; /* a5 */
  51. *(--stk) = 0xffffffff; /* a6 */
  52. *(--stk) = 0xffffffff; /* a7 */
  53. *(--stk) = 0xffffffff; /* s0/fp */
  54. *(--stk) = 0xffffffff; /* s1 */
  55. *(--stk) = 0xffffffff; /* s2 */
  56. *(--stk) = 0xffffffff; /* s3 */
  57. *(--stk) = 0xffffffff; /* s4 */
  58. *(--stk) = 0xffffffff; /* s5 */
  59. *(--stk) = 0xffffffff; /* s6 */
  60. *(--stk) = 0xffffffff; /* s7 */
  61. *(--stk) = 0xffffffff; /* s8 */
  62. *(--stk) = 0xffffffff; /* s9 */
  63. *(--stk) = 0xffffffff; /* s10*/
  64. *(--stk) = 0xffffffff; /* s11*/
  65. *(--stk) = 0xffffffff; /* t0 */
  66. *(--stk) = 0xffffffff; /* t1 */
  67. *(--stk) = 0xffffffff; /* t2 */
  68. *(--stk) = 0xffffffff; /* t3 */
  69. *(--stk) = 0xffffffff; /* t4 */
  70. *(--stk) = 0xffffffff; /* t5 */
  71. *(--stk) = 0xffffffff; /* t6 */
  72. *(--stk) = 0xffffffff; /* tp */
  73. *(--stk) = 0xffffffff; /* gp */
  74. *(--stk) = 0x880; /* mie */
  75. // *(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
  76. /* return task's current stack address */
  77. return (rt_uint8_t *)stk;
  78. }