stack.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2013, 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. * 2013-7-14 Peng Fan sep6200 implementation
  23. */
  24. #include <rtthread.h>
  25. #include <sep6200.h>
  26. /**
  27. * @addtogroup sep6200
  28. */
  29. /*@{*/
  30. /**
  31. * This function will initialize thread stack
  32. *
  33. * @param tentry the entry of thread
  34. * @param parameter the parameter of entry
  35. * @param stack_addr the beginning stack address
  36. * @param texit the function will be called when thread exit
  37. *
  38. * @return stack address
  39. */
  40. rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
  41. rt_uint8_t *stack_addr, void *texit)
  42. {
  43. rt_uint32_t *stk;
  44. stk = (rt_uint32_t*)stack_addr;
  45. *(stk) = (rt_uint32_t)tentry; /* entry point */
  46. *(--stk) = (rt_uint32_t)texit; /* lr */
  47. *(--stk) = 0; /* r28 */
  48. *(--stk) = 0; /* r27 */
  49. *(--stk) = 0; /* r26 */
  50. *(--stk) = 0; /* r25 */
  51. *(--stk) = 0; /* r24 */
  52. *(--stk) = 0; /* r23 */
  53. *(--stk) = 0; /* r22 */
  54. *(--stk) = 0; /* r21 */
  55. *(--stk) = 0; /* r20 */
  56. *(--stk) = 0; /* r19 */
  57. *(--stk) = 0; /* r18 */
  58. *(--stk) = 0; /* r17 */
  59. *(--stk) = 0; /* r16 */
  60. *(--stk) = 0; /* r15 */
  61. *(--stk) = 0; /* r14 */
  62. *(--stk) = 0; /* r13 */
  63. *(--stk) = 0; /* r12 */
  64. *(--stk) = 0; /* r11 */
  65. *(--stk) = 0; /* r10 */
  66. *(--stk) = 0; /* r9 */
  67. *(--stk) = 0; /* r8 */
  68. *(--stk) = 0; /* r7 */
  69. *(--stk) = 0; /* r6 */
  70. *(--stk) = 0; /* r5 */
  71. *(--stk) = 0; /* r4 */
  72. *(--stk) = 0; /* r3 */
  73. *(--stk) = 0; /* r2 */
  74. *(--stk) = 0; /* r1 */
  75. *(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
  76. *(--stk) = Mode_PRIV; /* asr */
  77. *(--stk) = Mode_PRIV; /* bsr */ /*why both PRIV do not need switch?*/
  78. /* return task's current stack address */
  79. return (rt_uint8_t *)stk;
  80. }
  81. /*@}*/