stack.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * File : stack.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, 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://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-09-23 Bernard the first version
  13. * 2011-10-05 Bernard add thumb mode
  14. */
  15. #include <rtthread.h>
  16. #include <board.h>
  17. /**
  18. * @addtogroup AM33xx
  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. rt_uint32_t *stk;
  35. stk = (rt_uint32_t*)stack_addr;
  36. *(stk) = (rt_uint32_t)tentry; /* entry point */
  37. *(--stk) = (rt_uint32_t)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) = (rt_uint32_t)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. /* return task's current stack address */
  57. return (rt_uint8_t *)stk;
  58. }
  59. /*@}*/